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] PHPUnit 9 support #30947

Merged
merged 2 commits into from Dec 27, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -79,13 +79,14 @@
"aws/aws-sdk-php": "^3.0",
"doctrine/dbal": "^2.6",
"filp/whoops": "^2.4",
"graham-campbell/testbench-core": "^3.1",
"guzzlehttp/guzzle": "^6.3",
"league/flysystem-cached-adapter": "^1.0",
"mockery/mockery": "^1.3.1",
"moontoast/math": "^1.1",
"orchestra/testbench-core": "^4.0",
"pda/pheanstalk": "^4.0",
"phpunit/phpunit": "^8.3",
"phpunit/phpunit": "^8.4|^9.0",
"predis/predis": "^1.1.1",
"symfony/cache": "^4.3.4"
},
Expand Down Expand Up @@ -121,6 +122,7 @@
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
"filp/whoops": "Required for friendly error pages in development (^2.4).",
"fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).",
"graham-campbell/testbench-core": "Required to use the foundation testing component with PHPUnit 9 (^3.1).",
"guzzlehttp/guzzle": "Required to use the Mailgun mail driver and the ping methods on schedules (^6.0).",
"laravel/tinker": "Required to use the tinker console command (^1.0).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
Expand Down
65 changes: 40 additions & 25 deletions src/Illuminate/Foundation/Testing/Assert.php
Expand Up @@ -3,40 +3,55 @@
namespace Illuminate\Foundation\Testing;

use ArrayAccess;
use Exception;
use GrahamCampbell\TestBenchCore\ArraySubsetTrait;
use PHPUnit\Framework\Assert as PHPUnit;
use PHPUnit\Framework\Constraint\ArraySubset;
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 (trait_exists(ArraySubsetTrait::class)) {
/**
* Asserts that an array has a specified subset.
*
* This method was taken over from PHPUnit where it was deprecated. See link for more info.
*
* @param \ArrayAccess|array $subset
* @param \ArrayAccess|array $array
* @param bool $checkForObjectIdentity
* @param string $message
* @return void
*
* @link https://github.com/sebastianbergmann/phpunit/issues/3494
* @internal This class is not meant to be used or overwritten outside the framework itself.
*/
public static function assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void
abstract class Assert extends PHPUnit
{
if (! (is_array($subset) || $subset instanceof ArrayAccess)) {
throw InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
}
use ArraySubsetTrait;
}
} 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.
*
* This method was taken over from PHPUnit where it was deprecated. See link for more info.
*
* @param \ArrayAccess|array $subset
* @param \ArrayAccess|array $array
* @param bool $checkForObjectIdentity
* @param string $message
* @return void
*/
public static function assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void
{
if ((int) Version::series()[0] > 8) {
throw new Exception('For PHPUnit 9 support, please install graham-campbell/testbench-core:"^3.1".');
}

if (! (is_array($array) || $array instanceof ArrayAccess)) {
throw InvalidArgumentHelper::factory(2, 'array or ArrayAccess');
}
if (! (is_array($subset) || $subset instanceof ArrayAccess)) {
throw InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
}

$constraint = new ArraySubset($subset, $checkForObjectIdentity);
if (! (is_array($array) || $array instanceof ArrayAccess)) {
throw InvalidArgumentHelper::factory(2, 'array or ArrayAccess');
}

static::assertThat($array, $constraint, $message);
$constraint = new ArraySubset($subset, $checkForObjectIdentity);

static::assertThat($array, $constraint, $message);
}
}
}
2 changes: 1 addition & 1 deletion tests/Foundation/FoundationProviderRepositoryTest.php
Expand Up @@ -92,7 +92,7 @@ public function testWriteManifestStoresToProperLocation()
public function testWriteManifestThrowsExceptionIfManifestDirDoesntExist()
{
$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/^The (.*) directory must be present and writable.$/');
$this->expectExceptionMessageMatches('/^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