diff --git a/composer.json b/composer.json index bcaaed20348c..3c76467d8010 100644 --- a/composer.json +++ b/composer.json @@ -86,7 +86,7 @@ "moontoast/math": "^1.1", "orchestra/testbench-core": "^4.0", "pda/pheanstalk": "^4.0", - "phpunit/phpunit": "^8.4|^9.0", + "phpunit/phpunit": "^7.5.15|^8.4|^9.0", "predis/predis": "^1.1.1", "symfony/cache": "^4.3.4" }, diff --git a/src/Illuminate/Foundation/Testing/Assert.php b/src/Illuminate/Foundation/Testing/Assert.php index 3a35bebe8852..f4075ab48f96 100644 --- a/src/Illuminate/Foundation/Testing/Assert.php +++ b/src/Illuminate/Foundation/Testing/Assert.php @@ -6,42 +6,65 @@ use Illuminate\Foundation\Testing\Constraints\ArraySubset; use PHPUnit\Framework\Assert as PHPUnit; use PHPUnit\Framework\InvalidArgumentException; +use PHPUnit\Runner\Version; use PHPUnit\Util\InvalidArgumentHelper; -/** - * @internal This class is not meant to be used or overwritten outside the framework itself. - */ -abstract class Assert extends PHPUnit -{ +if (class_exists(Version::class) && (int) Version::series()[0] >= 8) { /** - * Asserts that an array has a specified subset. - * - * @param \ArrayAccess|array $subset - * @param \ArrayAccess|array $array - * @param bool $checkForIdentity - * @param string $msg - * @return void + * @internal This class is not meant to be used or overwritten outside the framework itself. */ - public static function assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ''): void + abstract class Assert extends PHPUnit { - if (! (is_array($subset) || $subset instanceof ArrayAccess)) { - if (class_exists(InvalidArgumentException::class)) { - throw InvalidArgumentException::create(1, 'array or ArrayAccess'); - } else { - throw InvalidArgumentHelper::factory(1, 'array or ArrayAccess'); + /** + * Asserts that an array has a specified subset. + * + * @param \ArrayAccess|array $subset + * @param \ArrayAccess|array $array + * @param bool $checkForIdentity + * @param string $msg + * @return void + */ + public static function assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ''): void + { + if (! (is_array($subset) || $subset instanceof ArrayAccess)) { + if (class_exists(InvalidArgumentException::class)) { + throw InvalidArgumentException::create(1, 'array or ArrayAccess'); + } else { + throw InvalidArgumentHelper::factory(1, 'array or ArrayAccess'); + } } - } - if (! (is_array($array) || $array instanceof ArrayAccess)) { - if (class_exists(InvalidArgumentException::class)) { - throw InvalidArgumentException::create(2, 'array or ArrayAccess'); - } else { - throw InvalidArgumentHelper::factory(2, 'array or ArrayAccess'); + if (! (is_array($array) || $array instanceof ArrayAccess)) { + if (class_exists(InvalidArgumentException::class)) { + throw InvalidArgumentException::create(2, 'array or ArrayAccess'); + } else { + throw InvalidArgumentHelper::factory(2, 'array or ArrayAccess'); + } } - } - $constraint = new ArraySubset($subset, $checkForIdentity); + $constraint = new ArraySubset($subset, $checkForIdentity); - PHPUnit::assertThat($array, $constraint, $msg); + PHPUnit::assertThat($array, $constraint, $msg); + } + } +} else { + /** + * @internal This class is not meant to be used or overwritten outside the framework itself. + */ + abstract class Assert extends PHPUnit + { + /** + * Asserts that an array has a specified subset. + * + * @param \ArrayAccess|array $subset + * @param \ArrayAccess|array $array + * @param bool $checkForIdentity + * @param string $msg + * @return void + */ + public static function assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ''): void + { + PHPUnit::assertArraySubset($subset, $array, $checkForIdentity, $msg); + } } } diff --git a/src/Illuminate/Foundation/Testing/Constraints/ArraySubset.php b/src/Illuminate/Foundation/Testing/Constraints/ArraySubset.php index edfbf96d4ea6..9d07f461523a 100644 --- a/src/Illuminate/Foundation/Testing/Constraints/ArraySubset.php +++ b/src/Illuminate/Foundation/Testing/Constraints/ArraySubset.php @@ -143,7 +143,7 @@ private function toArray(iterable $other): array return (array) $other; } } -} else { +} elseif (class_exists(Version::class) && (int) Version::series()[0] >= 8) { /** * @internal This class is not meant to be used or overwritten outside the framework itself. */ diff --git a/tests/Foundation/FoundationProviderRepositoryTest.php b/tests/Foundation/FoundationProviderRepositoryTest.php index 06402d8685a2..c6c0095028b6 100755 --- a/tests/Foundation/FoundationProviderRepositoryTest.php +++ b/tests/Foundation/FoundationProviderRepositoryTest.php @@ -92,7 +92,12 @@ public function testWriteManifestStoresToProperLocation() public function testWriteManifestThrowsExceptionIfManifestDirDoesntExist() { $this->expectException(Exception::class); - $this->expectExceptionMessageMatches('/^The (.*) directory must be present and writable.$/'); + + if (is_callable([$this, 'expectExceptionMessageMatches'])) { + $this->expectExceptionMessageMatches('/^The (.*) directory must be present and writable.$/'); + } else { + $this->expectExceptionMessageRegExp('/^The (.*) directory must be present and writable.$/'); + } $repo = new ProviderRepository(m::mock(ApplicationContract::class), $files = m::mock(Filesystem::class), __DIR__.'/cache/services.php'); $files->shouldReceive('replace')->never();