Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Restore phpunit 7 support #31113

Merged
merged 6 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
77 changes: 50 additions & 27 deletions src/Illuminate/Foundation/Testing/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
7 changes: 6 additions & 1 deletion tests/Foundation/FoundationProviderRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down