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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7d06127b4ebc..ec12c8b4b4af 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.5.8', '10.0'] stability: [prefer-lowest, prefer-stable] - name: PHP ${{ matrix.php }} - ${{ matrix.stability }} + name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} steps: - name: Checkout code @@ -75,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: @@ -82,8 +90,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: + 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 != '10.0' + + - name: Execute tests against PHPUnit ^10 + run: vendor/bin/phpunit env: DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root @@ -91,6 +110,7 @@ jobs: DYNAMODB_ENDPOINT: "http://localhost:8888" AWS_ACCESS_KEY_ID: random_key AWS_SECRET_ACCESS_KEY: random_secret + if: matrix.phpunit == '10.0' - name: Store artifacts uses: actions/upload-artifact@v3 @@ -107,9 +127,10 @@ jobs: fail-fast: true matrix: php: [8.1, 8.2] + phpunit: ['9.5.8', '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 @@ -133,7 +154,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer require symfony/css-selector:~6.0 --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 @@ -143,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: @@ -150,11 +178,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 != '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 == '10.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/composer.json b/composer.json index 7e84ff6f2a05..4df2e87e5ad7 100644 --- a/composer.json +++ b/composer.json @@ -94,11 +94,11 @@ "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", - "phpunit/phpunit": "^9.5.8", + "phpunit/phpunit": "^9.5.8 || ^10.0.1", "predis/predis": "^2.0.2", "symfony/cache": "^6.2", "symfony/http-client": "^6.2.4" 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/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/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/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index a71a41a677cc..8df9f75951c4 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -163,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. * @@ -241,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()); + } } /** @@ -290,19 +312,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..cc2e570ae2f4 100644 --- a/src/Illuminate/Testing/Assert.php +++ b/src/Illuminate/Testing/Assert.php @@ -4,12 +4,8 @@ use ArrayAccess; use Illuminate\Testing\Constraints\ArraySubset; +use Illuminate\Testing\Exceptions\InvalidArgumentException; 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; /** * @internal This class is not meant to be used or overwritten outside the framework itself. @@ -39,41 +35,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/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/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php b/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php new file mode 100644 index 000000000000..c05ed94d8fb4 --- /dev/null +++ b/src/Illuminate/Testing/Exceptions/InvalidArgumentException.php @@ -0,0 +1,34 @@ +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..fed3a9dc8cc1 100755 --- a/tests/Cache/CacheApcStoreTest.php +++ b/tests/Cache/CacheApcStoreTest.php @@ -4,6 +4,7 @@ use Illuminate\Cache\ApcStore; use Illuminate\Cache\ApcWrapper; +use Mockery; use PHPUnit\Framework\TestCase; class CacheApcStoreTest extends TestCase @@ -53,14 +54,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/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(); 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/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/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/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/Foundation/Testing/TestCaseTest.php b/tests/Foundation/Testing/TestCaseTest.php index b26b596bf4fa..3611c3f9a6b3 100644 --- a/tests/Foundation/Testing/TestCaseTest.php +++ b/tests/Foundation/Testing/TestCaseTest.php @@ -16,19 +16,23 @@ 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'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + $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())) @@ -39,36 +43,51 @@ 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.')); + + $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'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + + $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']) ); $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + + $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'); @@ -79,7 +98,12 @@ public function test_it_doesnt_fail_with_encoded_json() $this->expectException(ExpectationFailedException::class); $this->expectExceptionMessageMatches('/Assertion message/s'); - $testCase->onNotSuccessfulTest(new ExpectationFailedException('Assertion message.')); + + $testCase::$latestResponse->transformNotSuccessfulException( + $exception = new ExpectationFailedException('Assertion message.'), + ); + + throw $exception; } public function tearDown(): void 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/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)); 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/Testing/AssertTest.php b/tests/Testing/AssertTest.php new file mode 100644 index 000000000000..d010fc483ab5 --- /dev/null +++ b/tests/Testing/AssertTest.php @@ -0,0 +1,92 @@ + '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'); + } +} 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']); 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; }