From 0d086f227be0c61c15b09e585b1aa4fa105e8f43 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 23 Dec 2022 16:30:10 +0000 Subject: [PATCH 01/34] Adds PHPUnit 10 support --- composer.json | 2 +- .../InteractsWithNotSuccessfulTests.php | 47 +++++++++++++++++++ .../Foundation/Testing/TestCase.php | 16 +------ src/Illuminate/Testing/Assert.php | 37 --------------- tests/Foundation/Testing/TestCaseTest.php | 23 +++++++-- 5 files changed, 67 insertions(+), 58 deletions(-) create mode 100644 src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php diff --git a/composer.json b/composer.json index 7e84ff6f2a05..e77924a6bd0b 100644 --- a/composer.json +++ b/composer.json @@ -98,7 +98,7 @@ "pda/pheanstalk": "^4.0", "phpstan/phpdoc-parser": "^1.15", "phpstan/phpstan": "^1.4.7", - "phpunit/phpunit": "^9.5.8", + "phpunit/phpunit": "^9.5.27 || ^10.0", "predis/predis": "^2.0.2", "symfony/cache": "^6.2", "symfony/http-client": "^6.2.4" diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php new file mode 100644 index 000000000000..8d47d7ef5e6b --- /dev/null +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php @@ -0,0 +1,47 @@ +transformNotSuccessfulException($exception) + ); + } + } +} else { + trait InteractsWithNotSuccessfulTests + { + /** + * This method is called when a test method did not execute successfully. + * + * @param \Throwable $exception + * @return void + */ + protected function onNotSuccessfulTest(Throwable $exception): void + { + parent::onNotSuccessfulTest( + is_null(static::$latestResponse) + ? $exception + : static::$latestResponse->transformNotSuccessfulException($exception) + ); + } + } +} diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index a71a41a677cc..538d5ee64958 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -27,6 +27,7 @@ abstract class TestCase extends BaseTestCase Concerns\InteractsWithDatabase, Concerns\InteractsWithDeprecationHandling, Concerns\InteractsWithExceptionHandling, + Concerns\InteractsWithNotSuccessfulTests, Concerns\InteractsWithSession, Concerns\InteractsWithTime, Concerns\InteractsWithViews; @@ -290,19 +291,4 @@ protected function callBeforeApplicationDestroyedCallbacks() } } } - - /** - * This method is called when a test method did not execute successfully. - * - * @param \Throwable $exception - * @return void - */ - protected function onNotSuccessfulTest(Throwable $exception): void - { - parent::onNotSuccessfulTest( - is_null(static::$latestResponse) - ? $exception - : static::$latestResponse->transformNotSuccessfulException($exception) - ); - } } diff --git a/src/Illuminate/Testing/Assert.php b/src/Illuminate/Testing/Assert.php index c0184b7b663e..5dd7c5cd0dae 100644 --- a/src/Illuminate/Testing/Assert.php +++ b/src/Illuminate/Testing/Assert.php @@ -39,41 +39,4 @@ public static function assertArraySubset($subset, $array, bool $checkForIdentity PHPUnit::assertThat($array, $constraint, $msg); } - - /** - * Asserts that a file does not exist. - * - * @param string $filename - * @param string $message - * @return void - */ - public static function assertFileDoesNotExist(string $filename, string $message = ''): void - { - static::assertThat($filename, new LogicalNot(new FileExists), $message); - } - - /** - * Asserts that a directory does not exist. - * - * @param string $directory - * @param string $message - * @return void - */ - public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void - { - static::assertThat($directory, new LogicalNot(new DirectoryExists), $message); - } - - /** - * Asserts that a string matches a given regular expression. - * - * @param string $pattern - * @param string $string - * @param string $message - * @return void - */ - public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void - { - static::assertThat($string, new RegularExpression($pattern), $message); - } } diff --git a/tests/Foundation/Testing/TestCaseTest.php b/tests/Foundation/Testing/TestCaseTest.php index b26b596bf4fa..b1b64ad1e7da 100644 --- a/tests/Foundation/Testing/TestCaseTest.php +++ b/tests/Foundation/Testing/TestCaseTest.php @@ -23,7 +23,9 @@ public function test_it_includes_response_exceptions_on_test_failures() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*Unexpected exception/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + (fn () => $this->onNotSuccessfulTest( + new ExpectationFailedException('Assertion message.')) + )->call($testCase); } public function test_it_includes_validation_errors_on_test_failures() @@ -39,7 +41,10 @@ public function test_it_includes_validation_errors_on_test_failures() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*The first name field is required/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + + (fn () => $testCase->onNotSuccessfulTest( + new ExpectationFailedException('Assertion message.')) + )->call($testCase); } public function test_it_includes_json_validation_errors_on_test_failures() @@ -51,7 +56,9 @@ public function test_it_includes_json_validation_errors_on_test_failures() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*The first name field is required/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + (fn () => $testCase->onNotSuccessfulTest( + new ExpectationFailedException('Assertion message.')) + )->call($testCase); } public function test_it_doesnt_fail_with_false_json() @@ -63,7 +70,10 @@ public function test_it_doesnt_fail_with_false_json() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + + (fn () => $testCase->onNotSuccessfulTest( + new ExpectationFailedException('Assertion message.')) + )->call($testCase); } public function test_it_doesnt_fail_with_encoded_json() @@ -79,7 +89,10 @@ public function test_it_doesnt_fail_with_encoded_json() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + + (fn () => $testCase->onNotSuccessfulTest( + new ExpectationFailedException('Assertion message.')) + )->call($testCase); } public function tearDown(): void From 54516ca67208a8054b54c163d89e929db4ff28bc Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 23 Dec 2022 16:31:39 +0000 Subject: [PATCH 02/34] Apply fixes from StyleCI --- src/Illuminate/Testing/Assert.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Illuminate/Testing/Assert.php b/src/Illuminate/Testing/Assert.php index 5dd7c5cd0dae..32aa4b9a8ba5 100644 --- a/src/Illuminate/Testing/Assert.php +++ b/src/Illuminate/Testing/Assert.php @@ -5,10 +5,6 @@ use ArrayAccess; use Illuminate\Testing\Constraints\ArraySubset; use PHPUnit\Framework\Assert as PHPUnit; -use PHPUnit\Framework\Constraint\DirectoryExists; -use PHPUnit\Framework\Constraint\FileExists; -use PHPUnit\Framework\Constraint\LogicalNot; -use PHPUnit\Framework\Constraint\RegularExpression; use PHPUnit\Framework\InvalidArgumentException; /** From feee4a06dfe8b26db0e754d9fb48f6e75cdf460b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 23 Dec 2022 22:33:20 +0000 Subject: [PATCH 03/34] Update composer.json Co-authored-by: Mior Muhammad Zaki --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e77924a6bd0b..d97c9dfd7be9 100644 --- a/composer.json +++ b/composer.json @@ -94,7 +94,7 @@ "league/flysystem-read-only": "^3.3", "league/flysystem-sftp-v3": "^3.0", "mockery/mockery": "^1.5.1", - "orchestra/testbench-core": "^8.0", + "orchestra/testbench-core": "dev-phpunit10", "pda/pheanstalk": "^4.0", "phpstan/phpdoc-parser": "^1.15", "phpstan/phpstan": "^1.4.7", From 04e785f524e2f9e167649862335ce0166776d135 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 23 Dec 2022 22:39:36 +0000 Subject: [PATCH 04/34] Ignores type error --- phpstan.src.neon.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.src.neon.dist b/phpstan.src.neon.dist index fcaf9ac45b64..814bd7629cb8 100644 --- a/phpstan.src.neon.dist +++ b/phpstan.src.neon.dist @@ -16,5 +16,6 @@ parameters: - "#Instantiated class [a-zA-Z0-9\\\\_]+ not found.#" - "#Unsafe usage of new static#" excludePaths: + - "src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php" - "src/Illuminate/Testing/ParallelRunner.php" - "src/Illuminate/Testing/Constraints/ArraySubset.php" From 21880ebd9b4be01e708acd6e96de1bea31a4d8d4 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 27 Dec 2022 09:56:49 +0100 Subject: [PATCH 05/34] Run PHPUnit v10 --- .github/workflows/tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7d06127b4ebc..f87f5c558cbe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,9 +40,10 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] + phpunit: ['9.0', '10.0'] stability: [prefer-lowest, prefer-stable] - name: PHP ${{ matrix.php }} - ${{ matrix.stability }} + name: PHP ${{ matrix.php }} - ${{ matrix.phpunit }} - ${{ matrix.stability }} steps: - name: Checkout code @@ -65,7 +66,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require symfony/css-selector:^6.0 --no-interaction --no-update + command: composer require phpunit/phpunit:^${{ matrix.phpunit }} symfony/css-selector:^6.0 --no-interaction --no-update - name: Set Minimum PHP 8.2 Versions uses: nick-fields/retry@v2 From ddefa081e75c0fc641c8aca090e9e721ecfe2334 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 27 Dec 2022 09:57:59 +0100 Subject: [PATCH 06/34] wip --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f87f5c558cbe..e0bceffec1f6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,7 +43,7 @@ jobs: phpunit: ['9.0', '10.0'] stability: [prefer-lowest, prefer-stable] - name: PHP ${{ matrix.php }} - ${{ matrix.phpunit }} - ${{ matrix.stability }} + name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} steps: - name: Checkout code From 567a2271dc3107c5eecfa3a61101362c3481d436 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 27 Dec 2022 13:33:59 +0000 Subject: [PATCH 07/34] Performs `transformNotSuccessfulException` when running the test --- .../InteractsWithNotSuccessfulTests.php | 47 ----------------- .../Foundation/Testing/TestCase.php | 21 +++++++- tests/Foundation/Testing/TestCaseTest.php | 52 ++++++++++++------- 3 files changed, 52 insertions(+), 68 deletions(-) delete mode 100644 src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php deleted file mode 100644 index 8d47d7ef5e6b..000000000000 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php +++ /dev/null @@ -1,47 +0,0 @@ -transformNotSuccessfulException($exception) - ); - } - } -} else { - trait InteractsWithNotSuccessfulTests - { - /** - * This method is called when a test method did not execute successfully. - * - * @param \Throwable $exception - * @return void - */ - protected function onNotSuccessfulTest(Throwable $exception): void - { - parent::onNotSuccessfulTest( - is_null(static::$latestResponse) - ? $exception - : static::$latestResponse->transformNotSuccessfulException($exception) - ); - } - } -} diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index 538d5ee64958..d2405f3387c2 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -27,7 +27,6 @@ abstract class TestCase extends BaseTestCase Concerns\InteractsWithDatabase, Concerns\InteractsWithDeprecationHandling, Concerns\InteractsWithExceptionHandling, - Concerns\InteractsWithNotSuccessfulTests, Concerns\InteractsWithSession, Concerns\InteractsWithTime, Concerns\InteractsWithViews; @@ -114,6 +113,26 @@ protected function refreshApplication() $this->app = $this->createApplication(); } + /** + * {@inheritdoc} + */ + protected function runTest(): mixed + { + $result = null; + + try { + $result = parent::runTest(); + } catch (Throwable $e) { + if (! is_null(static::$latestResponse)) { + static::$latestResponse->transformNotSuccessfulException($e); + } + + throw $e; + } + + return $result; + } + /** * Boot the testing helper traits. * diff --git a/tests/Foundation/Testing/TestCaseTest.php b/tests/Foundation/Testing/TestCaseTest.php index b1b64ad1e7da..962c1d603dfb 100644 --- a/tests/Foundation/Testing/TestCaseTest.php +++ b/tests/Foundation/Testing/TestCaseTest.php @@ -16,21 +16,24 @@ class TestCaseTest extends BaseTestCase { public function test_it_includes_response_exceptions_on_test_failures() { - $testCase = new ExampleTestCase(); + $testCase = new ExampleTestCase('foo'); $testCase::$latestResponse = TestResponse::fromBaseResponse(new Response()) ->withExceptions(collect([new Exception('Unexpected exception.')])); $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*Unexpected exception/s'); - (fn () => $this->onNotSuccessfulTest( - new ExpectationFailedException('Assertion message.')) - )->call($testCase); + + $testCase::$latestResponse->transformNotSuccessfulException( + $exception = new ExpectationFailedException('Assertion message.'), + ); + + throw $exception; } public function test_it_includes_validation_errors_on_test_failures() { - $testCase = new ExampleTestCase(); + $testCase = new ExampleTestCase('foo'); $testCase::$latestResponse = TestResponse::fromBaseResponse( tap(new RedirectResponse('/')) ->setSession(new Store('test-session', new NullSessionHandler())) @@ -42,28 +45,33 @@ public function test_it_includes_validation_errors_on_test_failures() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*The first name field is required/s'); - (fn () => $testCase->onNotSuccessfulTest( - new ExpectationFailedException('Assertion message.')) - )->call($testCase); + $testCase::$latestResponse->transformNotSuccessfulException( + $exception = new ExpectationFailedException('Assertion message.'), + ); + + throw $exception; } public function test_it_includes_json_validation_errors_on_test_failures() { - $testCase = new ExampleTestCase(); + $testCase = new ExampleTestCase('foo'); $testCase::$latestResponse = TestResponse::fromBaseResponse( new Response(['errors' => ['first_name' => 'The first name field is required.']]) ); $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*The first name field is required/s'); - (fn () => $testCase->onNotSuccessfulTest( - new ExpectationFailedException('Assertion message.')) - )->call($testCase); + + $testCase::$latestResponse->transformNotSuccessfulException( + $exception = new ExpectationFailedException('Assertion message.'), + ); + + throw $exception; } public function test_it_doesnt_fail_with_false_json() { - $testCase = new ExampleTestCase(); + $testCase = new ExampleTestCase('foo'); $testCase::$latestResponse = TestResponse::fromBaseResponse( new Response(false, 200, ['Content-Type' => 'application/json']) ); @@ -71,14 +79,16 @@ public function test_it_doesnt_fail_with_false_json() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message/s'); - (fn () => $testCase->onNotSuccessfulTest( - new ExpectationFailedException('Assertion message.')) - )->call($testCase); + $testCase::$latestResponse->transformNotSuccessfulException( + $exception = new ExpectationFailedException('Assertion message.'), + ); + + throw $exception; } public function test_it_doesnt_fail_with_encoded_json() { - $testCase = new ExampleTestCase(); + $testCase = new ExampleTestCase('foo'); $testCase::$latestResponse = TestResponse::fromBaseResponse( tap(new Response, function ($response) { $response->header('Content-Type', 'application/json'); @@ -90,9 +100,11 @@ public function test_it_doesnt_fail_with_encoded_json() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message/s'); - (fn () => $testCase->onNotSuccessfulTest( - new ExpectationFailedException('Assertion message.')) - )->call($testCase); + $testCase::$latestResponse->transformNotSuccessfulException( + $exception = new ExpectationFailedException('Assertion message.'), + ); + + throw $exception; } public function tearDown(): void From 350d3e17d81957a2c9e87600e293c317126b0f00 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 27 Dec 2022 13:35:42 +0000 Subject: [PATCH 08/34] Apply fixes from StyleCI --- tests/Foundation/Testing/TestCaseTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Foundation/Testing/TestCaseTest.php b/tests/Foundation/Testing/TestCaseTest.php index 962c1d603dfb..3611c3f9a6b3 100644 --- a/tests/Foundation/Testing/TestCaseTest.php +++ b/tests/Foundation/Testing/TestCaseTest.php @@ -23,7 +23,6 @@ public function test_it_includes_response_exceptions_on_test_failures() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message.*Unexpected exception/s'); - $testCase::$latestResponse->transformNotSuccessfulException( $exception = new ExpectationFailedException('Assertion message.'), ); From 6eb8eee3fb4f7710d629bbfd958926a5206868b6 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 27 Dec 2022 16:41:02 +0000 Subject: [PATCH 09/34] Fixes PHPUnit 10 tests --- .github/workflows/tests.yml | 12 +- .gitignore | 1 + phpunit.xml.dist | 10 +- phpunit9.xml.dist | 31 ++ src/Illuminate/Cache/FileStore.php | 8 +- .../Testing/Concerns/InteractsWithRedis.php | 6 +- .../Testing/Constraints/ArraySubset.php | 350 ++++++------------ tests/Auth/AuthAccessGateTest.php | 2 +- tests/Cache/CacheApcStoreTest.php | 27 +- tests/Cache/CacheArrayStoreTest.php | 6 +- tests/Encryption/EncrypterTest.php | 2 +- tests/Foundation/Testing/BootTraitsTest.php | 2 +- .../Integration/Routing/RouteRedirectTest.php | 2 +- tests/Support/LotteryTest.php | 4 +- tests/Support/SupportTestingBusFakeTest.php | 47 ++- tests/Support/SupportTestingEventFakeTest.php | 13 +- tests/Support/SupportTestingMailFakeTest.php | 17 +- .../SupportTestingNotificationFakeTest.php | 11 +- tests/Support/SupportTestingQueueFakeTest.php | 29 +- tests/Validation/ValidationAddFailureTest.php | 2 +- 20 files changed, 247 insertions(+), 335 deletions(-) create mode 100644 phpunit9.xml.dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e0bceffec1f6..17f2e3151c62 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -151,11 +151,19 @@ jobs: max_attempts: 5 command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - name: Execute tests - run: vendor/bin/phpunit --verbose + - name: Execute tests against PHPUnit ^9 + run: vendor/bin/phpunit --verbose --configuration phpunit9.xml.dist + env: + AWS_ACCESS_KEY_ID: random_key + AWS_SECRET_ACCESS_KEY: random_secret + if: matrix.phpunit == '9.0' + + - name: Execute tests against PHPUnit ^10 + run: vendor/bin/phpunit env: AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret + if : matrix.phpunit != '9.0' - name: Store artifacts uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index 40beb13032f9..39397245b7ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.phpunit.cache /vendor composer.phar composer.lock diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cc45c172e33c..7265cc649940 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,12 @@ + cacheDirectory=".phpunit.cache" + backupStaticProperties="false"> ./tests diff --git a/phpunit9.xml.dist b/phpunit9.xml.dist new file mode 100644 index 000000000000..cc45c172e33c --- /dev/null +++ b/phpunit9.xml.dist @@ -0,0 +1,31 @@ + + + + + ./tests + + + + + + + + + + diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index 42292295f0ce..1df7ccfa8a93 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -267,9 +267,15 @@ protected function getPayload($key) return $this->emptyPayload(); } + $e = null; + try { - $data = unserialize(substr($contents, 10)); + $data = @unserialize(substr($contents, 10)); } catch (Exception $e) { + // ... + } + + if ($data === false || ! is_null($e)) { $this->forget($key); return $this->emptyPayload(); diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php index e23ae4c3fd87..76a0f305a690 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php @@ -42,7 +42,7 @@ public function setUpRedis() $host = Env::get('REDIS_HOST', '127.0.0.1'); $port = Env::get('REDIS_PORT', 6379); - foreach ($this->redisDriverProvider() as $driver) { + foreach (static::redisDriverProvider() as $driver) { $this->redis[$driver[0]] = new RedisManager($app, $driver[0], [ 'cluster' => false, 'options' => [ @@ -80,7 +80,7 @@ public function tearDownRedis() $this->redis['phpredis']->connection()->flushdb(); } - foreach ($this->redisDriverProvider() as $driver) { + foreach (static::redisDriverProvider() as $driver) { if (isset($this->redis[$driver[0]])) { $this->redis[$driver[0]]->connection()->disconnect(); } @@ -92,7 +92,7 @@ public function tearDownRedis() * * @return array */ - public function redisDriverProvider() + public static function redisDriverProvider() { return [ ['predis'], diff --git a/src/Illuminate/Testing/Constraints/ArraySubset.php b/src/Illuminate/Testing/Constraints/ArraySubset.php index a4caeadb908b..01304afd6715 100644 --- a/src/Illuminate/Testing/Constraints/ArraySubset.php +++ b/src/Illuminate/Testing/Constraints/ArraySubset.php @@ -4,276 +4,140 @@ use ArrayObject; use PHPUnit\Framework\Constraint\Constraint; -use PHPUnit\Runner\Version; use SebastianBergmann\Comparator\ComparisonFailure; use Traversable; -if (class_exists(Version::class) && (int) Version::series()[0] >= 9) { +/** + * @internal This class is not meant to be used or overwritten outside the framework itself. + */ +final class ArraySubset extends Constraint +{ /** - * @internal This class is not meant to be used or overwritten outside the framework itself. + * @var iterable */ - final class ArraySubset extends Constraint - { - /** - * @var iterable - */ - private $subset; - - /** - * @var bool - */ - private $strict; - - /** - * Create a new array subset constraint instance. - * - * @param iterable $subset - * @param bool $strict - * @return void - */ - public function __construct(iterable $subset, bool $strict = false) - { - $this->strict = $strict; - $this->subset = $subset; - } - - /** - * Evaluates the constraint for parameter $other. - * - * If $returnResult is set to false (the default), an exception is thrown - * in case of a failure. null is returned otherwise. - * - * If $returnResult is true, the result of the evaluation is returned as - * a boolean value instead: true in case of success, false in case of a - * failure. - * - * @param mixed $other - * @param string $description - * @param bool $returnResult - * @return bool|null - * - * @throws \PHPUnit\Framework\ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - public function evaluate($other, string $description = '', bool $returnResult = false): ?bool - { - // type cast $other & $this->subset as an array to allow - // support in standard array functions. - $other = $this->toArray($other); - $this->subset = $this->toArray($this->subset); + private $subset; - $patched = array_replace_recursive($other, $this->subset); - - if ($this->strict) { - $result = $other === $patched; - } else { - $result = $other == $patched; - } - - if ($returnResult) { - return $result; - } + /** + * @var bool + */ + private $strict; - if (! $result) { - $f = new ComparisonFailure( - $patched, - $other, - var_export($patched, true), - var_export($other, true) - ); + /** + * Create a new array subset constraint instance. + * + * @param iterable $subset + * @param bool $strict + * @return void + */ + public function __construct(iterable $subset, bool $strict = false) + { + $this->strict = $strict; + $this->subset = $subset; + } - $this->fail($other, $description, $f); - } + /** + * Evaluates the constraint for parameter $other. + * + * If $returnResult is set to false (the default), an exception is thrown + * in case of a failure. null is returned otherwise. + * + * If $returnResult is true, the result of the evaluation is returned as + * a boolean value instead: true in case of success, false in case of a + * failure. + * + * @param mixed $other + * @param string $description + * @param bool $returnResult + * @return bool|null + * + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + */ + public function evaluate($other, string $description = '', bool $returnResult = false): ?bool + { + // type cast $other & $this->subset as an array to allow + // support in standard array functions. + $other = $this->toArray($other); + $this->subset = $this->toArray($this->subset); - return null; - } + $patched = array_replace_recursive($other, $this->subset); - /** - * Returns a string representation of the constraint. - * - * @return string - * - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - public function toString(): string - { - return 'has the subset '.$this->exporter()->export($this->subset); + if ($this->strict) { + $result = $other === $patched; + } else { + $result = $other == $patched; } - /** - * Returns the description of the failure. - * - * The beginning of failure messages is "Failed asserting that" in most - * cases. This method should return the second part of that sentence. - * - * @param mixed $other - * @return string - * - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - protected function failureDescription($other): string - { - return 'an array '.$this->toString(); + if ($returnResult) { + return $result; } - /** - * Returns the description of the failure. - * - * The beginning of failure messages is "Failed asserting that" in most - * cases. This method should return the second part of that sentence. - * - * @param iterable $other - * @return array - */ - private function toArray(iterable $other): array - { - if (is_array($other)) { - return $other; - } - - if ($other instanceof ArrayObject) { - return $other->getArrayCopy(); - } + if (! $result) { + $f = new ComparisonFailure( + $patched, + $other, + var_export($patched, true), + var_export($other, true) + ); - if ($other instanceof Traversable) { - return iterator_to_array($other); - } - - // Keep BC even if we know that array would not be the expected one - return (array) $other; + $this->fail($other, $description, $f); } + + return null; } -} else { + /** - * @internal This class is not meant to be used or overwritten outside the framework itself. + * Returns a string representation of the constraint. + * + * @return string + * + * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ - final class ArraySubset extends Constraint + public function toString(): string { - /** - * @var iterable - */ - private $subset; - - /** - * @var bool - */ - private $strict; - - /** - * Create a new array subset constraint instance. - * - * @param iterable $subset - * @param bool $strict - * @return void - */ - public function __construct(iterable $subset, bool $strict = false) - { - $this->strict = $strict; - $this->subset = $subset; - } - - /** - * Evaluates the constraint for parameter $other. - * - * If $returnResult is set to false (the default), an exception is thrown - * in case of a failure. null is returned otherwise. - * - * If $returnResult is true, the result of the evaluation is returned as - * a boolean value instead: true in case of success, false in case of a - * failure. - * - * @param mixed $other - * @param string $description - * @param bool $returnResult - * @return bool|null - * - * @throws \PHPUnit\Framework\ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - public function evaluate($other, string $description = '', bool $returnResult = false): ?bool - { - // type cast $other & $this->subset as an array to allow - // support in standard array functions. - $other = $this->toArray($other); - $this->subset = $this->toArray($this->subset); - - $patched = array_replace_recursive($other, $this->subset); - - if ($this->strict) { - $result = $other === $patched; - } else { - $result = $other == $patched; - } - - if ($returnResult) { - return $result; - } + return 'has the subset '.$this->exporter()->export($this->subset); + } - if (! $result) { - $f = new ComparisonFailure( - $patched, - $other, - var_export($patched, true), - var_export($other, true) - ); + /** + * Returns the description of the failure. + * + * The beginning of failure messages is "Failed asserting that" in most + * cases. This method should return the second part of that sentence. + * + * @param mixed $other + * @return string + * + * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + */ + protected function failureDescription($other): string + { + return 'an array '.$this->toString(); + } - $this->fail($other, $description, $f); - } + /** + * Returns the description of the failure. + * + * The beginning of failure messages is "Failed asserting that" in most + * cases. This method should return the second part of that sentence. + * + * @param iterable $other + * @return array + */ + private function toArray(iterable $other): array + { + if (is_array($other)) { + return $other; } - /** - * Returns a string representation of the constraint. - * - * @return string - * - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - public function toString(): string - { - return 'has the subset '.$this->exporter()->export($this->subset); + if ($other instanceof ArrayObject) { + return $other->getArrayCopy(); } - /** - * Returns the description of the failure. - * - * The beginning of failure messages is "Failed asserting that" in most - * cases. This method should return the second part of that sentence. - * - * @param mixed $other - * @return string - * - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - protected function failureDescription($other): string - { - return 'an array '.$this->toString(); + if ($other instanceof Traversable) { + return iterator_to_array($other); } - /** - * Returns the description of the failure. - * - * The beginning of failure messages is "Failed asserting that" in most - * cases. This method should return the second part of that sentence. - * - * @param iterable $other - * @return array - */ - private function toArray(iterable $other): array - { - if (is_array($other)) { - return $other; - } - - if ($other instanceof ArrayObject) { - return $other->getArrayCopy(); - } - - if ($other instanceof Traversable) { - return iterator_to_array($other); - } - - // Keep BC even if we know that array would not be the expected one - return (array) $other; - } + // Keep BC even if we know that array would not be the expected one + return (array) $other; } } diff --git a/tests/Auth/AuthAccessGateTest.php b/tests/Auth/AuthAccessGateTest.php index 7c2b92d8f3b9..0074fe51ba53 100644 --- a/tests/Auth/AuthAccessGateTest.php +++ b/tests/Auth/AuthAccessGateTest.php @@ -584,7 +584,7 @@ public function testAuthorizeThrowsUnauthorizedException() { $this->expectException(AuthorizationException::class); $this->expectExceptionMessage('You are not an admin.'); - $this->expectExceptionCode(null); + $this->expectExceptionCode(0); $gate = $this->getBasicGate(); diff --git a/tests/Cache/CacheApcStoreTest.php b/tests/Cache/CacheApcStoreTest.php index d9f7e137bfb8..20b7800919e6 100755 --- a/tests/Cache/CacheApcStoreTest.php +++ b/tests/Cache/CacheApcStoreTest.php @@ -4,6 +4,8 @@ use Illuminate\Cache\ApcStore; use Illuminate\Cache\ApcWrapper; +use Mockery; +use Mockery\Mock; use PHPUnit\Framework\TestCase; class CacheApcStoreTest extends TestCase @@ -53,14 +55,23 @@ public function testSetMethodProperlyCallsAPC() public function testSetMultipleMethodProperlyCallsAPC() { - $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock(); - $apc->expects($this->exactly(3))->method('put')->withConsecutive([ - $this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(60), - ], [ - $this->equalTo('baz'), $this->equalTo('qux'), $this->equalTo(60), - ], [ - $this->equalTo('bar'), $this->equalTo('norf'), $this->equalTo(60), - ])->willReturn(true); + $apc = Mockery::mock(ApcWrapper::class); + + $apc->shouldReceive('put') + ->once() + ->with('foo', 'bar', 60) + ->andReturn(true); + + $apc->shouldReceive('put') + ->once() + ->with('baz', 'qux', 60) + ->andReturn(true); + + $apc->shouldReceive('put') + ->once() + ->with('bar', 'norf', 60) + ->andReturn(true); + $store = new ApcStore($apc); $result = $store->putMany([ 'foo' => 'bar', diff --git a/tests/Cache/CacheArrayStoreTest.php b/tests/Cache/CacheArrayStoreTest.php index 2fcd5a4d57c3..76d4fe70a6ea 100755 --- a/tests/Cache/CacheArrayStoreTest.php +++ b/tests/Cache/CacheArrayStoreTest.php @@ -248,7 +248,8 @@ public function testValuesAreNotStoredByReference() $store->put('object', $object, 10); $object->bar = true; - $this->assertObjectNotHasAttribute('bar', $store->get('object')); + $this->assertInstanceOf(stdClass::class, $store->get('object')); + $this->assertFalse(isset($store->get('object')->bar)); } public function testValuesAreStoredByReferenceIfSerializationIsDisabled() @@ -260,7 +261,8 @@ public function testValuesAreStoredByReferenceIfSerializationIsDisabled() $store->put('object', $object, 10); $object->bar = true; - $this->assertObjectHasAttribute('bar', $store->get('object')); + $this->assertInstanceOf(stdClass::class, $store->get('object')); + $this->assertTrue($store->get('object')->bar); } public function testReleasingLockAfterAlreadyForceReleasedByAnotherOwnerFails() diff --git a/tests/Encryption/EncrypterTest.php b/tests/Encryption/EncrypterTest.php index a720ad6cacfb..c6a0f1d28143 100755 --- a/tests/Encryption/EncrypterTest.php +++ b/tests/Encryption/EncrypterTest.php @@ -205,7 +205,7 @@ public function testSupportedMethodAcceptsAnyCasing() $this->assertTrue(Encrypter::supported($key, 'aes-128-cbc')); } - public function provideTamperedData() + public static function provideTamperedData() { $validIv = base64_encode(str_repeat('.', 16)); diff --git a/tests/Foundation/Testing/BootTraitsTest.php b/tests/Foundation/Testing/BootTraitsTest.php index 15bc4973332f..9519983b549c 100644 --- a/tests/Foundation/Testing/BootTraitsTest.php +++ b/tests/Foundation/Testing/BootTraitsTest.php @@ -33,7 +33,7 @@ class BootTraitsTest extends TestCase { public function testSetUpAndTearDownTraits() { - $testCase = new TestCaseWithTrait; + $testCase = new TestCaseWithTrait('foo'); $method = new ReflectionMethod($testCase, 'setUpTraits'); tap($method)->setAccessible(true)->invoke($testCase); diff --git a/tests/Integration/Routing/RouteRedirectTest.php b/tests/Integration/Routing/RouteRedirectTest.php index 4d32dd76d548..34dc3c38fb9f 100644 --- a/tests/Integration/Routing/RouteRedirectTest.php +++ b/tests/Integration/Routing/RouteRedirectTest.php @@ -20,7 +20,7 @@ public function testRouteRedirect($redirectFrom, $redirectTo, $requestUri, $redi $response->assertStatus(301); } - public function routeRedirectDataSets() + public static function routeRedirectDataSets() { return [ 'route redirect with no parameters' => ['from', 'to', '/from', '/to'], diff --git a/tests/Support/LotteryTest.php b/tests/Support/LotteryTest.php index a4dbe451fcdb..7dc3a31d856f 100644 --- a/tests/Support/LotteryTest.php +++ b/tests/Support/LotteryTest.php @@ -142,14 +142,14 @@ public function testItCanHandleMissingSequenceItems() $this->assertSame('winner', $result); $this->expectException(RuntimeException::class); - $this->expectErrorMessage('Missing key in sequence.'); + $this->expectExceptionMessage('Missing key in sequence.'); Lottery::odds(1, 10000)->winner(fn () => 'winner')->loser(fn () => 'loser')->choose(); } public function testItThrowsForFloatsOverOne() { $this->expectException(RuntimeException::class); - $this->expectErrorMessage('Float must not be greater than 1.'); + $this->expectExceptionMessage('Float must not be greater than 1.'); new Lottery(1.1); } diff --git a/tests/Support/SupportTestingBusFakeTest.php b/tests/Support/SupportTestingBusFakeTest.php index 9b70ddd2bc02..a2eb9f2ce41a 100644 --- a/tests/Support/SupportTestingBusFakeTest.php +++ b/tests/Support/SupportTestingBusFakeTest.php @@ -8,7 +8,6 @@ use Illuminate\Support\Testing\Fakes\BatchRepositoryFake; use Illuminate\Support\Testing\Fakes\BusFake; use Mockery as m; -use PHPUnit\Framework\Constraint\ExceptionMessage; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -49,7 +48,7 @@ public function testAssertDispatched() $this->fake->assertDispatched(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched.', $e->getMessage()); } $this->fake->dispatch(new BusJobStub); @@ -72,7 +71,7 @@ public function testAssertDispatchedAfterResponse() $this->fake->assertDispatchedAfterResponse(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched after sending the response.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched after sending the response.', $e->getMessage()); } $this->fake->dispatchAfterResponse(new BusJobStub); @@ -88,7 +87,7 @@ public function testAssertDispatchedAfterResponseClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched after sending the response.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched after sending the response.', $e->getMessage()); } } @@ -98,7 +97,7 @@ public function testAssertDispatchedSync() $this->fake->assertDispatchedSync(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched synchronously.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched synchronously.', $e->getMessage()); } $this->fake->dispatch(new BusJobStub); @@ -107,7 +106,7 @@ public function testAssertDispatchedSync() $this->fake->assertDispatchedSync(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched synchronously.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched synchronously.', $e->getMessage()); } $this->fake->dispatchSync(new BusJobStub); @@ -123,7 +122,7 @@ public function testAssertDispatchedSyncClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched synchronously.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was not dispatched synchronously.', $e->getMessage()); } } @@ -143,7 +142,7 @@ public function testAssertDispatchedWithCallbackInt() $this->fake->assertDispatched(BusJobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatched(BusJobStub::class, 2); @@ -158,7 +157,7 @@ public function testAssertDispatchedAfterResponseWithCallbackInt() $this->fake->assertDispatchedAfterResponse(BusJobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatchedAfterResponse(BusJobStub::class, 2); @@ -173,7 +172,7 @@ public function testAssertDispatchedSyncWithCallbackInt() $this->fake->assertDispatchedSync(BusJobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatchedSync(BusJobStub::class, 2); @@ -190,7 +189,7 @@ public function testAssertDispatchedWithCallbackFunction() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was not dispatched.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was not dispatched.', $e->getMessage()); } $this->fake->assertDispatched(OtherBusJobStub::class, function ($job) { @@ -213,7 +212,7 @@ public function testAssertDispatchedAfterResponseWithCallbackFunction() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was not dispatched after sending the response.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was not dispatched after sending the response.', $e->getMessage()); } $this->fake->assertDispatchedAfterResponse(OtherBusJobStub::class, function ($job) { @@ -236,7 +235,7 @@ public function testAssertDispatchedSyncWithCallbackFunction() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was not dispatched synchronously.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was not dispatched synchronously.', $e->getMessage()); } $this->fake->assertDispatchedSync(OtherBusJobStub::class, function ($job) { @@ -257,7 +256,7 @@ public function testAssertDispatchedTimes() $this->fake->assertDispatchedTimes(BusJobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatchedTimes(BusJobStub::class, 2); @@ -272,7 +271,7 @@ public function testAssertDispatchedAfterResponseTimes() $this->fake->assertDispatchedAfterResponseTimes(BusJobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatchedAfterResponseTimes(BusJobStub::class, 2); @@ -287,7 +286,7 @@ public function testAssertDispatchedSyncTimes() $this->fake->assertDispatchedSyncTimes(BusJobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatchedSyncTimes(BusJobStub::class, 2); @@ -304,7 +303,7 @@ public function testAssertNotDispatched() $this->fake->assertNotDispatched(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched.', $e->getMessage()); } } @@ -319,7 +318,7 @@ public function testAssertNotDispatchedWithClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched.', $e->getMessage()); } } @@ -333,7 +332,7 @@ public function testAssertNotDispatchedAfterResponse() $this->fake->assertNotDispatchedAfterResponse(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched after sending the response.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched after sending the response.', $e->getMessage()); } } @@ -347,7 +346,7 @@ public function testAssertNotDispatchedAfterResponseClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched after sending the response.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched after sending the response.', $e->getMessage()); } } @@ -361,7 +360,7 @@ public function testAssertNotDispatchedSync() $this->fake->assertNotDispatchedSync(BusJobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched synchronously.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched synchronously.', $e->getMessage()); } } @@ -375,7 +374,7 @@ public function testAssertNotDispatchedSyncClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched synchronously.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\BusJobStub] job was dispatched synchronously.', $e->getMessage()); } } @@ -389,7 +388,7 @@ public function testAssertNothingDispatched() $this->fake->assertNothingDispatched(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('Jobs were dispatched unexpectedly.')); + $this->assertStringContainsString('Jobs were dispatched unexpectedly.', $e->getMessage()); } } @@ -513,7 +512,7 @@ public function testAssertNothingBatched() $this->fake->assertNothingBatched(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('Batched jobs were dispatched unexpectedly.')); + $this->assertStringContainsString('Batched jobs were dispatched unexpectedly.', $e->getMessage()); } } diff --git a/tests/Support/SupportTestingEventFakeTest.php b/tests/Support/SupportTestingEventFakeTest.php index fbf7a1ab2738..e04edac4a9b1 100644 --- a/tests/Support/SupportTestingEventFakeTest.php +++ b/tests/Support/SupportTestingEventFakeTest.php @@ -5,7 +5,6 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Testing\Fakes\EventFake; use Mockery as m; -use PHPUnit\Framework\Constraint\ExceptionMessage; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -31,7 +30,7 @@ public function testAssertDispatched() $this->fake->assertDispatched(EventStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\EventStub] event was not dispatched.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was not dispatched.', $e->getMessage()); } $this->fake->dispatch(EventStub::class); @@ -71,7 +70,7 @@ public function testAssertDispatchedWithCallbackInt() $this->fake->assertDispatched(EventStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatched(EventStub::class, 2); @@ -86,7 +85,7 @@ public function testAssertDispatchedTimes() $this->fake->assertDispatchedTimes(EventStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertDispatchedTimes(EventStub::class, 2); @@ -102,7 +101,7 @@ public function testAssertNotDispatched() $this->fake->assertNotDispatched(EventStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\EventStub] event was dispatched.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\EventStub] event was dispatched.', $e->getMessage()); } } @@ -116,7 +115,7 @@ public function testAssertNotDispatchedWithClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\EventStub] event was dispatched.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\EventStub] event was dispatched.', $e->getMessage()); } } @@ -152,7 +151,7 @@ public function testAssertNothingDispatched() $this->fake->assertNothingDispatched(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('2 unexpected events were dispatched.')); + $this->assertStringContainsString('2 unexpected events were dispatched.', $e->getMessage()); } } } diff --git a/tests/Support/SupportTestingMailFakeTest.php b/tests/Support/SupportTestingMailFakeTest.php index e46cef255b4c..752a30daacd3 100644 --- a/tests/Support/SupportTestingMailFakeTest.php +++ b/tests/Support/SupportTestingMailFakeTest.php @@ -6,7 +6,6 @@ use Illuminate\Contracts\Translation\HasLocalePreference; use Illuminate\Mail\Mailable; use Illuminate\Support\Testing\Fakes\MailFake; -use PHPUnit\Framework\Constraint\ExceptionMessage; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -35,7 +34,7 @@ public function testAssertSent() $this->fake->assertSent(MailableStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\MailableStub] mailable was not sent.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was not sent.', $e->getMessage()); } $this->fake->to('taylor@laravel.com')->send($this->mailable); @@ -91,7 +90,7 @@ public function testAssertNotSent() $this->fake->assertNotSent(MailableStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\MailableStub] mailable was sent.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\MailableStub] mailable was sent.', $e->getMessage()); } } @@ -120,7 +119,7 @@ public function testAssertSentTimes() $this->fake->assertSent(MailableStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\MailableStub] mailable was sent 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was sent 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertSent(MailableStub::class, 2); @@ -132,7 +131,7 @@ public function testAssertQueued() $this->fake->assertQueued(MailableStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\MailableStub] mailable was not queued.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was not queued.', $e->getMessage()); } $this->fake->to('taylor@laravel.com')->queue($this->mailable); @@ -149,7 +148,7 @@ public function testAssertQueuedTimes() $this->fake->assertQueued(MailableStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\MailableStub] mailable was queued 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was queued 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertQueued(MailableStub::class, 2); @@ -165,7 +164,7 @@ public function testSendQueuesAMailableThatShouldBeQueued() $this->fake->assertSent(QueueableMailableStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\QueueableMailableStub] mailable was not sent.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\QueueableMailableStub] mailable was not sent.', $e->getMessage()); } } @@ -179,7 +178,7 @@ public function testAssertNothingSent() $this->fake->assertNothingSent(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The following mailables were sent unexpectedly: Illuminate\Tests\Support\MailableStub')); + $this->assertStringContainsString('The following mailables were sent unexpectedly: Illuminate\Tests\Support\MailableStub', $e->getMessage()); } } @@ -193,7 +192,7 @@ public function testAssertNothingQueued() $this->fake->assertNothingQueued(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The following mailables were queued unexpectedly: Illuminate\Tests\Support\MailableStub')); + $this->assertStringContainsString('The following mailables were queued unexpectedly: Illuminate\Tests\Support\MailableStub', $e->getMessage()); } } diff --git a/tests/Support/SupportTestingNotificationFakeTest.php b/tests/Support/SupportTestingNotificationFakeTest.php index 5668ba07bda0..878296c18e42 100644 --- a/tests/Support/SupportTestingNotificationFakeTest.php +++ b/tests/Support/SupportTestingNotificationFakeTest.php @@ -9,7 +9,6 @@ use Illuminate\Notifications\Notification; use Illuminate\Support\Collection; use Illuminate\Support\Testing\Fakes\NotificationFake; -use PHPUnit\Framework\Constraint\ExceptionMessage; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -45,7 +44,7 @@ public function testAssertSentTo() $this->fake->assertSentTo($this->user, NotificationStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\NotificationStub] notification was not sent.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\NotificationStub] notification was not sent.', $e->getMessage()); } $this->fake->send($this->user, new NotificationStub); @@ -88,7 +87,7 @@ public function testAssertNotSentTo() $this->fake->assertNotSentTo($this->user, NotificationStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\NotificationStub] notification was sent.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\NotificationStub] notification was sent.', $e->getMessage()); } } @@ -102,7 +101,7 @@ public function testAssertNotSentToClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\NotificationStub] notification was sent.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\NotificationStub] notification was sent.', $e->getMessage()); } } @@ -115,7 +114,7 @@ public function testAssertNothingSent() $this->fake->assertNothingSent(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('Notifications were sent unexpectedly.')); + $this->assertStringContainsString('Notifications were sent unexpectedly.', $e->getMessage()); } } @@ -128,7 +127,7 @@ public function testAssertNothingSentTo() $this->fake->assertNothingSentTo($this->user); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('Notifications were sent unexpectedly.')); + $this->assertStringContainsString('Notifications were sent unexpectedly.', $e->getMessage()); } } diff --git a/tests/Support/SupportTestingQueueFakeTest.php b/tests/Support/SupportTestingQueueFakeTest.php index 32f80ef5c005..b1d2afefbf25 100644 --- a/tests/Support/SupportTestingQueueFakeTest.php +++ b/tests/Support/SupportTestingQueueFakeTest.php @@ -8,7 +8,6 @@ use Illuminate\Queue\QueueManager; use Illuminate\Support\Testing\Fakes\QueueFake; use Mockery as m; -use PHPUnit\Framework\Constraint\ExceptionMessage; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -44,7 +43,7 @@ public function testAssertPushed() $this->fake->assertPushed(JobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.', $e->getMessage()); } $this->fake->push($this->job); @@ -110,7 +109,7 @@ public function testAssertNotPushed() $this->fake->assertNotPushed(JobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\JobStub] job was pushed.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\JobStub] job was pushed.', $e->getMessage()); } } @@ -126,7 +125,7 @@ public function testAssertNotPushedWithClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\JobStub] job was pushed.')); + $this->assertStringContainsString('The unexpected [Illuminate\Tests\Support\JobStub] job was pushed.', $e->getMessage()); } } @@ -138,7 +137,7 @@ public function testAssertPushedOn() $this->fake->assertPushedOn('bar', JobStub::class); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.', $e->getMessage()); } $this->fake->assertPushedOn('foo', JobStub::class); @@ -154,7 +153,7 @@ public function testAssertPushedOnWithClosure() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.', $e->getMessage()); } $this->fake->assertPushedOn('foo', function (JobStub $job) { @@ -171,7 +170,7 @@ public function testAssertPushedTimes() $this->fake->assertPushed(JobStub::class, 1); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\JobStub] job was pushed 2 times instead of 1 times.')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobStub] job was pushed 2 times instead of 1 times.', $e->getMessage()); } $this->fake->assertPushed(JobStub::class, 2); @@ -187,7 +186,7 @@ public function testAssertNothingPushed() $this->fake->assertNothingPushed(); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('Jobs were pushed unexpectedly.')); + $this->assertStringContainsString('Jobs were pushed unexpectedly.', $e->getMessage()); } } @@ -273,7 +272,7 @@ public function testAssertPushedWithChainUsingCallback() }); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected chain was not pushed')); + $this->assertStringContainsString('The expected chain was not pushed.', $e->getMessage()); } } @@ -283,7 +282,7 @@ public function testAssertPushedWithChainErrorHandling() $this->fake->assertPushedWithChain(JobWithChainStub::class, []); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\JobWithChainStub] job was not pushed')); + $this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobWithChainStub] job was not pushed.', $e->getMessage()); } $this->fake->push(new JobWithChainStub([ @@ -294,7 +293,7 @@ public function testAssertPushedWithChainErrorHandling() $this->fake->assertPushedWithChain(JobWithChainStub::class, []); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected chain can not be empty')); + $this->assertStringContainsString('The expected chain can not be empty.', $e->getMessage()); } try { @@ -304,7 +303,7 @@ public function testAssertPushedWithChainErrorHandling() ]); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected chain was not pushed')); + $this->assertStringContainsString('The expected chain was not pushed.', $e->getMessage()); } try { @@ -314,7 +313,7 @@ public function testAssertPushedWithChainErrorHandling() ]); $this->fail(); } catch (ExpectationFailedException $e) { - $this->assertThat($e, new ExceptionMessage('The expected chain was not pushed')); + $this->assertStringContainsString('The expected chain was not pushed.', $e->getMessage()); } } @@ -323,9 +322,9 @@ public function testCallUndefinedMethodErrorHandling() try { $this->fake->undefinedMethod(); } catch (BadMethodCallException $e) { - $this->assertThat($e, new ExceptionMessage(sprintf( + $this->assertSame(sprintf( 'Call to undefined method %s::%s()', get_class($this->fake), 'undefinedMethod' - ))); + ), $e->getMessage()); } } diff --git a/tests/Validation/ValidationAddFailureTest.php b/tests/Validation/ValidationAddFailureTest.php index 20fa5e43706f..dd65f9f7a4f9 100644 --- a/tests/Validation/ValidationAddFailureTest.php +++ b/tests/Validation/ValidationAddFailureTest.php @@ -14,7 +14,7 @@ class ValidationAddFailureTest extends TestCase */ public function makeValidator() { - $mainTest = new ValidationValidatorTest; + $mainTest = new ValidationValidatorTest('foo'); $trans = $mainTest->getIlluminateArrayTranslator(); return new Validator($trans, ['foo' => ['bar' => ['baz' => '']]], ['foo.bar.baz' => 'sometimes|required']); From b047fd07f0ace608a53370da943d4ca4bcac35c9 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 27 Dec 2022 16:41:19 +0000 Subject: [PATCH 10/34] Apply fixes from StyleCI --- tests/Cache/CacheApcStoreTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Cache/CacheApcStoreTest.php b/tests/Cache/CacheApcStoreTest.php index 20b7800919e6..fed3a9dc8cc1 100755 --- a/tests/Cache/CacheApcStoreTest.php +++ b/tests/Cache/CacheApcStoreTest.php @@ -5,7 +5,6 @@ use Illuminate\Cache\ApcStore; use Illuminate\Cache\ApcWrapper; use Mockery; -use Mockery\Mock; use PHPUnit\Framework\TestCase; class CacheApcStoreTest extends TestCase From 58756a20b7bae6962a060bea3dd48a83973d5822 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 27 Dec 2022 16:41:53 +0000 Subject: [PATCH 11/34] Removes non needed exclude path on types --- phpstan.src.neon.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.src.neon.dist b/phpstan.src.neon.dist index 814bd7629cb8..fcaf9ac45b64 100644 --- a/phpstan.src.neon.dist +++ b/phpstan.src.neon.dist @@ -16,6 +16,5 @@ parameters: - "#Instantiated class [a-zA-Z0-9\\\\_]+ not found.#" - "#Unsafe usage of new static#" excludePaths: - - "src/Illuminate/Foundation/Testing/Concerns/InteractsWithNotSuccessfulTests.php" - "src/Illuminate/Testing/ParallelRunner.php" - "src/Illuminate/Testing/Constraints/ArraySubset.php" From 31ac1589e4ebcfeae61d27748a465c10cc7fddd8 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 27 Dec 2022 16:59:38 +0000 Subject: [PATCH 12/34] Fixes tests on linux --- .github/workflows/tests.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 17f2e3151c62..0fe17e6c952f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -83,8 +83,8 @@ jobs: max_attempts: 5 command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - name: Execute tests - run: vendor/bin/phpunit --verbose + - name: Execute tests against PHPUnit ^9 + run: vendor/bin/phpunit --verbose --configuration phpunit9.xml.dist env: DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root @@ -92,6 +92,19 @@ jobs: DYNAMODB_ENDPOINT: "http://localhost:8888" AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret + if: matrix.phpunit == '9.0' + + - name: Execute tests against PHPUnit ^10 + run: vendor/bin/phpunit + env: + DB_PORT: ${{ job.services.mysql.ports[3306] }} + DB_USERNAME: root + DYNAMODB_CACHE_TABLE: laravel_dynamodb_test + DYNAMODB_ENDPOINT: "http://localhost:8888" + AWS_ACCESS_KEY_ID: random_key + AWS_SECRET_ACCESS_KEY: random_secret + if : matrix.phpunit != '9.0' + - name: Store artifacts uses: actions/upload-artifact@v3 From 3d42c57c2bf5e51af56b7529551315144d20ba35 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 27 Dec 2022 17:01:39 +0000 Subject: [PATCH 13/34] Adjusts tests on Windows --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0fe17e6c952f..9ecefeb14788 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -121,9 +121,10 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] + phpunit: ['9.0', '10.0'] stability: [prefer-lowest, prefer-stable] - name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - Windows + name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows steps: - name: Set git to use LF From b195c85be8e3196cddfa2676906928fbff408d71 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 27 Dec 2022 17:15:35 +0000 Subject: [PATCH 14/34] Fixes type issues on PHPUnit 10 --- tests/Queue/RedisQueueIntegrationTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Queue/RedisQueueIntegrationTest.php b/tests/Queue/RedisQueueIntegrationTest.php index ae54171c80c3..e7d26522f1e4 100644 --- a/tests/Queue/RedisQueueIntegrationTest.php +++ b/tests/Queue/RedisQueueIntegrationTest.php @@ -150,7 +150,7 @@ public function testPopProperlyPopsJobOffOfRedis($driver) $this->assertEquals(1, $this->redis[$driver]->connection()->zcard('queues:default:reserved')); $result = $this->redis[$driver]->connection()->zrangebyscore('queues:default:reserved', -INF, INF, ['withscores' => true]); $reservedJob = array_keys($result)[0]; - $score = $result[$reservedJob]; + $score = (int) $result[$reservedJob]; $this->assertLessThanOrEqual($score, $before + 60); $this->assertGreaterThanOrEqual($score, $after + 60); $this->assertEquals($job, unserialize(json_decode($reservedJob)->data->command)); @@ -177,7 +177,7 @@ public function testPopProperlyPopsDelayedJobOffOfRedis($driver) $this->assertEquals(1, $this->redis[$driver]->connection()->zcard('queues:default:reserved')); $result = $this->redis[$driver]->connection()->zrangebyscore('queues:default:reserved', -INF, INF, ['withscores' => true]); $reservedJob = array_keys($result)[0]; - $score = $result[$reservedJob]; + $score = (int) $result[$reservedJob]; $this->assertLessThanOrEqual($score, $before + 60); $this->assertGreaterThanOrEqual($score, $after + 60); $this->assertEquals($job, unserialize(json_decode($reservedJob)->data->command)); @@ -207,7 +207,7 @@ public function testPopPopsDelayedJobOffOfRedisWhenExpireNull($driver) $this->assertEquals(1, $this->redis[$driver]->connection()->zcard('queues:default:reserved')); $result = $this->redis[$driver]->connection()->zrangebyscore('queues:default:reserved', -INF, INF, ['withscores' => true]); $reservedJob = array_keys($result)[0]; - $score = $result[$reservedJob]; + $score = (int) $result[$reservedJob]; $this->assertLessThanOrEqual($score, $before); $this->assertGreaterThanOrEqual($score, $after); $this->assertEquals($job, unserialize(json_decode($reservedJob)->data->command)); @@ -302,6 +302,8 @@ public function testNotExpireJobsWhenExpireNull($driver) $this->assertInstanceOf(RedisQueueIntegrationTestJob::class, $command); $this->assertContains($command->i, [10, -20]); + $score = (int) $score; + if ($command->i == 10) { $this->assertLessThanOrEqual($score, $before); $this->assertGreaterThanOrEqual($score, $after); @@ -335,7 +337,7 @@ public function testExpireJobsWhenExpireSet($driver) $this->assertEquals(1, $this->redis[$driver]->connection()->zcard('queues:default:reserved')); $result = $this->redis[$driver]->connection()->zrangebyscore('queues:default:reserved', -INF, INF, ['withscores' => true]); $reservedJob = array_keys($result)[0]; - $score = $result[$reservedJob]; + $score = (int) $result[$reservedJob]; $this->assertLessThanOrEqual($score, $before + 30); $this->assertGreaterThanOrEqual($score, $after + 30); $this->assertEquals($job, unserialize(json_decode($reservedJob)->data->command)); From 1bc1e9f1fc2a71cab7c98c8035ab9050de02d9a1 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 28 Dec 2022 11:36:32 +0000 Subject: [PATCH 15/34] Removes at `@` --- src/Illuminate/Cache/FileStore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index 1df7ccfa8a93..c9560ededa1b 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -270,7 +270,7 @@ protected function getPayload($key) $e = null; try { - $data = @unserialize(substr($contents, 10)); + $data = unserialize(substr($contents, 10)); } catch (Exception $e) { // ... } From 1b71cde11ad2b41a732943258c90a315be1863f7 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 28 Dec 2022 11:44:18 +0000 Subject: [PATCH 16/34] Fixes missing variable --- src/Illuminate/Cache/FileStore.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index c9560ededa1b..6e78968760b8 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -268,6 +268,7 @@ protected function getPayload($key) } $e = null; + $data = false; try { $data = unserialize(substr($contents, 10)); From d541049ac14e6e26fb4e58e26c0ca1d40b67021a Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 09:37:01 +0000 Subject: [PATCH 17/34] Removes wrong test instead --- src/Illuminate/Cache/FileStore.php | 7 ------- tests/Cache/CacheFileStoreTest.php | 15 --------------- 2 files changed, 22 deletions(-) diff --git a/src/Illuminate/Cache/FileStore.php b/src/Illuminate/Cache/FileStore.php index 6e78968760b8..42292295f0ce 100755 --- a/src/Illuminate/Cache/FileStore.php +++ b/src/Illuminate/Cache/FileStore.php @@ -267,16 +267,9 @@ protected function getPayload($key) return $this->emptyPayload(); } - $e = null; - $data = false; - try { $data = unserialize(substr($contents, 10)); } catch (Exception $e) { - // ... - } - - if ($data === false || ! is_null($e)) { $this->forget($key); return $this->emptyPayload(); diff --git a/tests/Cache/CacheFileStoreTest.php b/tests/Cache/CacheFileStoreTest.php index 667ee0f162e7..97ca9ba8b187 100755 --- a/tests/Cache/CacheFileStoreTest.php +++ b/tests/Cache/CacheFileStoreTest.php @@ -28,21 +28,6 @@ public function testNullIsReturnedIfFileDoesntExist() $this->assertNull($value); } - public function testUnserializableFileContentGetDeleted() - { - $files = $this->mockFilesystem(); - $hash = sha1('foo'); - $cachePath = __DIR__.'/'.substr($hash, 0, 2).'/'.substr($hash, 2, 2).'/'.$hash; - - $files->expects($this->once())->method('get')->willReturn('9999999999-I_am_unserializableee: \(~_~)/'); - $files->expects($this->once())->method('exists')->with($this->equalTo($cachePath))->willReturn(true); - $files->expects($this->once())->method('delete')->with($this->equalTo($cachePath)); - - $value = (new FileStore($files, __DIR__))->get('foo'); - - $this->assertNull($value); - } - public function testPutCreatesMissingDirectories() { $files = $this->mockFilesystem(); From f0612223d9d163282b7158b7381ba9094cf417a9 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 09:52:40 +0000 Subject: [PATCH 18/34] Fixes tests on Windows --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9ecefeb14788..4dda894d3daf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -105,7 +105,6 @@ jobs: AWS_SECRET_ACCESS_KEY: random_secret if : matrix.phpunit != '9.0' - - name: Store artifacts uses: actions/upload-artifact@v3 with: @@ -148,7 +147,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require symfony/css-selector:~6.0 --no-interaction --no-update + command: composer require phpunit/phpunit:^${{ matrix.phpunit }} symfony/css-selector:~6.0 --no-interaction --no-update - name: Set Minimum PHP 8.2 Versions uses: nick-fields/retry@v2 From c3818fdd42fcbd251c3feaa787d2eb5ed81ca97c Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 13:21:59 +0000 Subject: [PATCH 19/34] Adjusts tests --- tests/Database/DatabaseQueryBuilderTest.php | 4 ++-- tests/Events/EventsDispatcherTest.php | 8 ++++++-- tests/Validation/ValidationValidatorTest.php | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index b84c1c7e9bc3..4bc95fc73ab9 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -2024,7 +2024,7 @@ public function testWhereNot() public function testIncrementManyArgumentValidation1() { $this->expectException(InvalidArgumentException::class); - $this->expectErrorMessage('Non-numeric value passed as increment amount for column: \'col\'.'); + $this->expectExceptionMessage('Non-numeric value passed as increment amount for column: \'col\'.'); $builder = $this->getBuilder(); $builder->from('users')->incrementEach(['col' => 'a']); } @@ -2032,7 +2032,7 @@ public function testIncrementManyArgumentValidation1() public function testIncrementManyArgumentValidation2() { $this->expectException(InvalidArgumentException::class); - $this->expectErrorMessage('Non-associative array passed to incrementEach method.'); + $this->expectExceptionMessage('Non-associative array passed to incrementEach method.'); $builder = $this->getBuilder(); $builder->from('users')->incrementEach([11 => 11]); } diff --git a/tests/Events/EventsDispatcherTest.php b/tests/Events/EventsDispatcherTest.php index 22670f370f46..60d78559b7c0 100755 --- a/tests/Events/EventsDispatcherTest.php +++ b/tests/Events/EventsDispatcherTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Tests\Events; +use Error; use Exception; use Illuminate\Container\Container; use Illuminate\Events\Dispatcher; @@ -574,8 +575,11 @@ public function testInvokeIsCalled() // It throws an "Error" when there is no method to be called. $d = new Dispatcher; $d->listen('myEvent', TestListenerLean::class); - $this->expectError(); - $this->expectErrorMessage('Call to undefined method '.TestListenerLean::class.'::__invoke()'); + $e = null; + + $this->expectException(Error::class); + $this->expectExceptionMessage('Call to undefined method '.TestListenerLean::class.'::__invoke()'); + $d->dispatch('myEvent', 'somePayload'); unset($_SERVER['__event.test']); diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 2532ad5c3ea7..edc4ec18d3a0 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -803,7 +803,9 @@ public function testCustomException() $v = new Validator($trans, ['name' => ''], ['name' => 'required']); - $exception = new class($v) extends ValidationException {}; + $exception = new class($v) extends ValidationException + { + }; $v->setException($exception); try { @@ -1647,7 +1649,7 @@ public function testProhibitedRulesAreConsistent($rules, $data, $result) $this->assertSame($result, (new Validator($trans, $data, $rules))->passes()); } - public function prohibitedRulesData() + public static function prohibitedRulesData() { $emptyCountable = new class implements Countable { @@ -8229,28 +8231,36 @@ public function getIlluminateArrayTranslator() class ImplicitTableModel extends Model { protected $guarded = []; + public $timestamps = false; } class ExplicitTableModel extends Model { protected $table = 'explicits'; + protected $guarded = []; + public $timestamps = false; } class ExplicitPrefixedTableModel extends Model { protected $table = 'prefix.explicits'; + protected $guarded = []; + public $timestamps = false; } class ExplicitTableAndConnectionModel extends Model { protected $table = 'explicits'; + protected $connection = 'connection'; + protected $guarded = []; + public $timestamps = false; } From 680ddd98c256f2c982b5420fce9d83b9a8e1a34d Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 13:40:02 +0000 Subject: [PATCH 20/34] Sets PHPUnit on its own step --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4dda894d3daf..fc504ebcf498 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -147,7 +147,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} symfony/css-selector:~6.0 --no-interaction --no-update + command: composer require phpunit/phpunit:^${{ matrix.phpunit }} symfony/css-selector:~6.0 ramsey/collection:^1.2 brick/math:^0.9.3 --no-interaction --no-update - name: Set Minimum PHP 8.2 Versions uses: nick-fields/retry@v2 From 32708ac38f5e1797ee14a6b223ce5ea86ee8c8c5 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 14:12:53 +0000 Subject: [PATCH 21/34] Adjusts workflow --- .github/workflows/tests.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fc504ebcf498..11fc6b829609 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -76,6 +76,13 @@ jobs: command: composer require guzzlehttp/guzzle:^7.5 guzzlehttp/psr7:^2.4 predis/predis:^2.0.2 --no-interaction --no-update if: matrix.php >= 8.2 + - name: Set PHPUnit + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update + - name: Install dependencies uses: nick-fields/retry@v2 with: @@ -95,7 +102,7 @@ jobs: if: matrix.phpunit == '9.0' - name: Execute tests against PHPUnit ^10 - run: vendor/bin/phpunit + run: vendor/bin/phpunit --verbose env: DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root @@ -103,7 +110,7 @@ jobs: DYNAMODB_ENDPOINT: "http://localhost:8888" AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret - if : matrix.phpunit != '9.0' + if: matrix.phpunit != '9.0' - name: Store artifacts uses: actions/upload-artifact@v3 @@ -157,6 +164,13 @@ jobs: command: composer require guzzlehttp/guzzle:~7.5 guzzlehttp/psr7:~2.4 predis/predis:~2.0.2 --no-interaction --no-update if: matrix.php >= 8.2 + - name: Set PHPUnit + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update + - name: Install dependencies uses: nick-fields/retry@v2 with: @@ -176,7 +190,7 @@ jobs: env: AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret - if : matrix.phpunit != '9.0' + if: matrix.phpunit != '9.0' - name: Store artifacts uses: actions/upload-artifact@v3 From d503c24e03db4e6b2033a053b1d31fb7cdac327b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 14:20:35 +0000 Subject: [PATCH 22/34] Removes verbose from PHPUnit 10 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 11fc6b829609..5a03dd544cc7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -102,7 +102,7 @@ jobs: if: matrix.phpunit == '9.0' - name: Execute tests against PHPUnit ^10 - run: vendor/bin/phpunit --verbose + run: vendor/bin/phpunit env: DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root From 174d1bc2c14630ba8112ed304ffe979b53356f23 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 30 Jan 2023 15:42:14 +0100 Subject: [PATCH 23/34] Update tests.yml --- .github/workflows/tests.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5a03dd544cc7..9d8fad186bf8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,7 +40,7 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] - phpunit: ['9.0', '10.0'] + phpunit: ['9.5.27', '10.0'] stability: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} @@ -81,7 +81,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update + command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update - name: Install dependencies uses: nick-fields/retry@v2 @@ -99,7 +99,7 @@ jobs: DYNAMODB_ENDPOINT: "http://localhost:8888" AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret - if: matrix.phpunit == '9.0' + if: matrix.phpunit != '10.0' - name: Execute tests against PHPUnit ^10 run: vendor/bin/phpunit @@ -110,7 +110,7 @@ jobs: DYNAMODB_ENDPOINT: "http://localhost:8888" AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret - if: matrix.phpunit != '9.0' + if: matrix.phpunit == '10.0' - name: Store artifacts uses: actions/upload-artifact@v3 @@ -127,7 +127,7 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] - phpunit: ['9.0', '10.0'] + phpunit: ['9.5.27', '10.0'] stability: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows @@ -169,7 +169,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update + command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update - name: Install dependencies uses: nick-fields/retry@v2 @@ -183,14 +183,14 @@ jobs: env: AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret - if: matrix.phpunit == '9.0' + if: matrix.phpunit != '10.0' - name: Execute tests against PHPUnit ^10 run: vendor/bin/phpunit env: AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret - if: matrix.phpunit != '9.0' + if: matrix.phpunit == '10.0' - name: Store artifacts uses: actions/upload-artifact@v3 From e411b144dc7fab2e2e70cccb55b053da2f07e3a5 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 30 Jan 2023 16:03:29 +0100 Subject: [PATCH 24/34] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d97c9dfd7be9..8e485f15581e 100644 --- a/composer.json +++ b/composer.json @@ -98,7 +98,7 @@ "pda/pheanstalk": "^4.0", "phpstan/phpdoc-parser": "^1.15", "phpstan/phpstan": "^1.4.7", - "phpunit/phpunit": "^9.5.27 || ^10.0", + "phpunit/phpunit": "^9.5.8 || ^10.0", "predis/predis": "^2.0.2", "symfony/cache": "^6.2", "symfony/http-client": "^6.2.4" From a4c51c8072e7cd3248b5277f89c2df57836843c7 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 30 Jan 2023 16:03:55 +0100 Subject: [PATCH 25/34] Update tests.yml --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d8fad186bf8..98ec71ee3619 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,7 +40,7 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] - phpunit: ['9.5.27', '10.0'] + phpunit: ['9.5.8', '10.0'] stability: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} @@ -127,7 +127,7 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] - phpunit: ['9.5.27', '10.0'] + phpunit: ['9.5.8', '10.0'] stability: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows From a932241a1e284504731c8051e0e09a134ae2ceef Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 19:10:42 +0000 Subject: [PATCH 26/34] Removes non needed files --- .github/workflows/tests.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 98ec71ee3619..e5181c41532f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -76,13 +76,6 @@ jobs: command: composer require guzzlehttp/guzzle:^7.5 guzzlehttp/psr7:^2.4 predis/predis:^2.0.2 --no-interaction --no-update if: matrix.php >= 8.2 - - name: Set PHPUnit - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update - - name: Install dependencies uses: nick-fields/retry@v2 with: @@ -164,13 +157,6 @@ jobs: command: composer require guzzlehttp/guzzle:~7.5 guzzlehttp/psr7:~2.4 predis/predis:~2.0.2 --no-interaction --no-update if: matrix.php >= 8.2 - - name: Set PHPUnit - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update - - name: Install dependencies uses: nick-fields/retry@v2 with: From 9a6d16daa709292d73781a44dda83f03084e1edb Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 30 Jan 2023 19:19:27 +0000 Subject: [PATCH 27/34] Setups PHPUnit as extra step --- .github/workflows/tests.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e5181c41532f..ec12c8b4b4af 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -66,7 +66,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} symfony/css-selector:^6.0 --no-interaction --no-update + command: composer require symfony/css-selector:^6.0 --no-interaction --no-update - name: Set Minimum PHP 8.2 Versions uses: nick-fields/retry@v2 @@ -76,6 +76,13 @@ jobs: command: composer require guzzlehttp/guzzle:^7.5 guzzlehttp/psr7:^2.4 predis/predis:^2.0.2 --no-interaction --no-update if: matrix.php >= 8.2 + - name: Set PHPUnit + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update + - name: Install dependencies uses: nick-fields/retry@v2 with: @@ -147,7 +154,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} symfony/css-selector:~6.0 ramsey/collection:^1.2 brick/math:^0.9.3 --no-interaction --no-update + command: composer require symfony/css-selector:~6.0 ramsey/collection:^1.2 brick/math:^0.9.3 --no-interaction --no-update - name: Set Minimum PHP 8.2 Versions uses: nick-fields/retry@v2 @@ -157,6 +164,13 @@ jobs: command: composer require guzzlehttp/guzzle:~7.5 guzzlehttp/psr7:~2.4 predis/predis:~2.0.2 --no-interaction --no-update if: matrix.php >= 8.2 + - name: Set PHPUnit + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update + - name: Install dependencies uses: nick-fields/retry@v2 with: From e369ca7c65311d868187cc5ef8dda95c9085684d Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 3 Feb 2023 15:00:12 +0000 Subject: [PATCH 28/34] Removes `--verbose` from workflows --- .github/workflows/databases.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/databases.yml b/.github/workflows/databases.yml index b21686c826dd..0d3d57310d7e 100644 --- a/.github/workflows/databases.yml +++ b/.github/workflows/databases.yml @@ -46,7 +46,7 @@ jobs: command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Database --verbose + run: vendor/bin/phpunit tests/Integration/Database env: DB_CONNECTION: mysql DB_USERNAME: root @@ -89,7 +89,7 @@ jobs: command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Database --verbose + run: vendor/bin/phpunit tests/Integration/Database env: DB_CONNECTION: mysql DB_USERNAME: root @@ -132,7 +132,7 @@ jobs: command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Database --verbose + run: vendor/bin/phpunit tests/Integration/Database env: DB_CONNECTION: mysql DB_USERNAME: root @@ -176,7 +176,7 @@ jobs: command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Database --verbose + run: vendor/bin/phpunit tests/Integration/Database env: DB_CONNECTION: pgsql DB_PASSWORD: password @@ -218,7 +218,7 @@ jobs: command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Database --verbose + run: vendor/bin/phpunit tests/Integration/Database env: DB_CONNECTION: sqlsrv DB_DATABASE: master From 10d799c678f0c7db2577539f70dd16b4aff338c4 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 3 Feb 2023 15:18:21 +0000 Subject: [PATCH 29/34] Fixes missing `Registry` class --- src/Illuminate/Foundation/Testing/TestCase.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index d2405f3387c2..bdd84029da6b 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -261,10 +261,12 @@ public static function tearDownAfterClass(): void { static::$latestResponse = null; - (function () { - $this->classDocBlocks = []; - $this->methodDocBlocks = []; - })->call(Registry::getInstance()); + if (class_exists(Registry::class)) { + (function () { + $this->classDocBlocks = []; + $this->methodDocBlocks = []; + })->call(Registry::getInstance()); + } } /** From 233eaa0e1a8f4c6c1d857b75a3305b63ed3671ef Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 3 Feb 2023 16:02:24 +0000 Subject: [PATCH 30/34] Bumps phpunit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8e485f15581e..4df2e87e5ad7 100644 --- a/composer.json +++ b/composer.json @@ -98,7 +98,7 @@ "pda/pheanstalk": "^4.0", "phpstan/phpdoc-parser": "^1.15", "phpstan/phpstan": "^1.4.7", - "phpunit/phpunit": "^9.5.8 || ^10.0", + "phpunit/phpunit": "^9.5.8 || ^10.0.1", "predis/predis": "^2.0.2", "symfony/cache": "^6.2", "symfony/http-client": "^6.2.4" From 56626b3683a13c509b5af92acce9c9526dc88478 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 3 Feb 2023 16:02:39 +0000 Subject: [PATCH 31/34] Fixes and adds tests for `assertArraySubset` --- phpstan.src.neon.dist | 1 - src/Illuminate/Testing/Assert.php | 2 +- .../Exceptions/InvalidArgumentException.php | 33 +++++++ tests/Testing/AssertTest.php | 92 +++++++++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/Illuminate/Testing/Exceptions/InvalidArgumentException.php create mode 100644 tests/Testing/AssertTest.php diff --git a/phpstan.src.neon.dist b/phpstan.src.neon.dist index fcaf9ac45b64..3062fdb4b4e0 100644 --- a/phpstan.src.neon.dist +++ b/phpstan.src.neon.dist @@ -17,4 +17,3 @@ parameters: - "#Unsafe usage of new static#" excludePaths: - "src/Illuminate/Testing/ParallelRunner.php" - - "src/Illuminate/Testing/Constraints/ArraySubset.php" diff --git a/src/Illuminate/Testing/Assert.php b/src/Illuminate/Testing/Assert.php index 32aa4b9a8ba5..cc2e570ae2f4 100644 --- a/src/Illuminate/Testing/Assert.php +++ b/src/Illuminate/Testing/Assert.php @@ -4,8 +4,8 @@ use ArrayAccess; use Illuminate\Testing\Constraints\ArraySubset; +use Illuminate\Testing\Exceptions\InvalidArgumentException; use PHPUnit\Framework\Assert as PHPUnit; -use PHPUnit\Framework\InvalidArgumentException; /** * @internal This class is not meant to be used or overwritten outside the framework itself. diff --git a/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php b/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php new file mode 100644 index 000000000000..efb3dccc62db --- /dev/null +++ b/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php @@ -0,0 +1,33 @@ + 'string', + 'object' => new stdClass(), + ], [ + 'int' => 1, + 'string' => 'string', + 'object' => new stdClass(), + ]); + } + + public function testArraySubsetMayFail() + { + $this->expectException(ExpectationFailedException::class); + + Assert::assertArraySubset([ + 'int' => 2, + 'string' => 'string', + 'object' => new stdClass(), + ], [ + 'int' => 1, + 'string' => 'string', + 'object' => new stdClass(), + ]); + } + + public function testArraySubsetWithStrict() + { + Assert::assertArraySubset([ + 'string' => 'string', + 'object' => $object = new stdClass(), + ], [ + 'int' => 1, + 'string' => 'string', + 'object' => $object, + ], true); + } + + public function testArraySubsetWithStrictMayFail() + { + $this->expectException(ExpectationFailedException::class); + + Assert::assertArraySubset([ + 'string' => 'string', + 'object' => new stdClass(), + ], [ + 'int' => 1, + 'string' => 'string', + 'object' => new stdClass(), + ], true); + } + + public function testArraySubsetMayFailIfArrayIsNotArray() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'Argument #1 of Illuminate\Testing\Assert::assertArraySubset() must be an array or ArrayAccess' + ); + + Assert::assertArraySubset('string', [ + 'int' => 1, + 'string' => 'string', + 'object' => new stdClass(), + ]); + } + + public function testArraySubsetMayFailIfSubsetIsNotArray() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + 'Argument #2 of Illuminate\Testing\Assert::assertArraySubset() must be an array or ArrayAccess' + ); + + Assert::assertArraySubset([ + 'string' => 'string', + 'object' => new stdClass(), + ], 'string'); + } +} From ed669a6102359c21f9012926868c89d871e87946 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 3 Feb 2023 16:03:05 +0000 Subject: [PATCH 32/34] Apply fixes from StyleCI --- tests/Testing/AssertTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Testing/AssertTest.php b/tests/Testing/AssertTest.php index 995b2c67c16c..d010fc483ab5 100644 --- a/tests/Testing/AssertTest.php +++ b/tests/Testing/AssertTest.php @@ -3,8 +3,8 @@ namespace Illuminate\Tests\Testing; use Illuminate\Testing\Assert; -use PHPUnit\Framework\ExpectationFailedException; use Illuminate\Testing\Exceptions\InvalidArgumentException; +use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use stdClass; From 5f5ab9c5a364aef8780f52748dca25ad2ee0d423 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 3 Feb 2023 10:25:06 -0600 Subject: [PATCH 33/34] Update InvalidArgumentException.php --- src/Illuminate/Testing/Exceptions/InvalidArgumentException.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php b/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php index efb3dccc62db..c05ed94d8fb4 100644 --- a/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php +++ b/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php @@ -14,6 +14,7 @@ class InvalidArgumentException extends Exception public static function create(int $argument, string $type): static { $stack = debug_backtrace(); + $function = $stack[1]['function']; if (isset($stack[1]['class'])) { From f451f0c28838daad0ba237932f5b5ebaadaee067 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 3 Feb 2023 10:26:18 -0600 Subject: [PATCH 34/34] Update TestCase.php --- .../Foundation/Testing/TestCase.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index bdd84029da6b..8df9f75951c4 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -113,26 +113,6 @@ protected function refreshApplication() $this->app = $this->createApplication(); } - /** - * {@inheritdoc} - */ - protected function runTest(): mixed - { - $result = null; - - try { - $result = parent::runTest(); - } catch (Throwable $e) { - if (! is_null(static::$latestResponse)) { - static::$latestResponse->transformNotSuccessfulException($e); - } - - throw $e; - } - - return $result; - } - /** * Boot the testing helper traits. * @@ -183,6 +163,26 @@ protected function setUpTraits() return $uses; } + /** + * {@inheritdoc} + */ + protected function runTest(): mixed + { + $result = null; + + try { + $result = parent::runTest(); + } catch (Throwable $e) { + if (! is_null(static::$latestResponse)) { + static::$latestResponse->transformNotSuccessfulException($e); + } + + throw $e; + } + + return $result; + } + /** * Clean up the testing environment before the next test. *