Skip to content

Commit

Permalink
Merge pull request #1053 from martinssipenko/phpunit9
Browse files Browse the repository at this point in the history
Add support for PHPUnit version 9
  • Loading branch information
davedevelopment committed May 14, 2020
2 parents a115dc3 + 969980f commit f24033d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -36,7 +36,7 @@
"hamcrest/hamcrest-php": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0"
"phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0|~9.0"
},
"autoload": {
"psr-0": {
Expand Down
7 changes: 6 additions & 1 deletion library/Mockery/Adapter/Phpunit/Legacy/TestListenerTrait.php
Expand Up @@ -85,6 +85,11 @@ public function endTest(Test $test, $time)

public function startTestSuite()
{
Blacklist::$blacklistedClassNames[\Mockery::class] = 1;
if (method_exists(Blacklist::class, 'addDirectory')) {
(new BlackList())->getBlacklistedDirectories();
Blacklist::addDirectory(\dirname((new \ReflectionClass(\Mockery::class))->getFileName()));
} else {
Blacklist::$blacklistedClassNames[\Mockery::class] = 1;
}
}
}
18 changes: 18 additions & 0 deletions library/Mockery/Adapter/Phpunit/MockeryTestCase.php
Expand Up @@ -37,4 +37,22 @@ protected function mockeryTestSetUp()
protected function mockeryTestTearDown()
{
}

public function expectExceptionMessageRegEx($regularExpression)
{
if (method_exists(get_parent_class(), 'expectExceptionMessageRegExp')) {
return parent::expectExceptionMessageRegExp($regularExpression);
}

return $this->expectExceptionMessageMatches($regularExpression);
}

public static function assertMatchesRegEx($pattern, $string, $message = '')
{
if (method_exists(get_parent_class(), 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
}

self::assertRegExp($pattern, $string, $message);
}
}
22 changes: 19 additions & 3 deletions tests/Mockery/Adapter/Phpunit/TestListenerTest.php
Expand Up @@ -96,8 +96,24 @@ public function testMockeryIsAddedToBlacklist()
{
$suite = \Mockery::mock(\PHPUnit\Framework\TestSuite::class);

$this->assertArrayNotHasKey(\Mockery::class, \PHPUnit\Util\Blacklist::$blacklistedClassNames);
$this->listener->startTestSuite($suite);
$this->assertSame(1, \PHPUnit\Util\Blacklist::$blacklistedClassNames[\Mockery::class]);
if (method_exists(\PHPUnit\Util\Blacklist::class, 'addDirectory')) {
$this->assertFalse(
(new \PHPUnit\Util\Blacklist())->isBlacklisted(
(new \ReflectionClass(\Mockery::class))->getFileName()
)
);

$this->listener->startTestSuite($suite);

$this->assertTrue(
(new \PHPUnit\Util\Blacklist())->isBlacklisted(
(new \ReflectionClass(\Mockery::class))->getFileName()
)
);
} else {
$this->assertArrayNotHasKey(\Mockery::class, \PHPUnit\Util\Blacklist::$blacklistedClassNames);
$this->listener->startTestSuite($suite);
$this->assertSame(1, \PHPUnit\Util\Blacklist::$blacklistedClassNames[\Mockery::class]);
}
}
}
6 changes: 3 additions & 3 deletions tests/Mockery/ContainerTest.php
Expand Up @@ -37,7 +37,7 @@ public function testGetKeyOfDemeterMockShouldReturnKeyWhenMatchingMock()
{
$m = mock();
$m->shouldReceive('foo->bar');
$this->assertRegExp(
$this->assertMatchesRegEx(
'/Mockery_(\d+)__demeter_([0-9a-f]+)_foo/',
Mockery::getContainer()->getKeyOfDemeterMockFor('foo', get_class($m))
);
Expand Down Expand Up @@ -455,7 +455,7 @@ public function testCantCallMethodWhenUsingBlacklistAndNoExpectation()
{
$m = mock('MockeryTest_PartialNormalClass2[!foo]');
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/::bar\(\), but no expectations were specified/');
$this->expectExceptionMessageRegEx('/::bar\(\), but no expectations were specified/');
$m->bar();
}

Expand Down Expand Up @@ -801,7 +801,7 @@ public function testInstantiationOfInstanceMockWithConstructorParameterValidatio
->andThrow(new \Exception('instanceMock ' . rand(100, 999)));

$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/^instanceMock \d{3}$/');
$this->expectExceptionMessageRegEx('/^instanceMock \d{3}$/');
new MyNamespace\MyClass16();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Mockery/ExpectationTest.php
Expand Up @@ -428,15 +428,15 @@ public function testExpectsStringArgumentExceptionMessageDifferentiatesBetweenNu
{
$this->mock->shouldReceive('foo')->withArgs(array('a string'));
$this->expectException(\Mockery\Exception::class);
$this->expectExceptionMessageRegExp('/foo\(NULL\)/');
$this->expectExceptionMessageRegEx('/foo\(NULL\)/');
$this->mock->foo(null);
Mockery::close();
}

public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArgumentType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/invalid argument (.+), only array and closure are allowed/');
$this->expectExceptionMessageRegEx('/invalid argument (.+), only array and closure are allowed/');
$this->mock->shouldReceive('foo')->withArgs(5);
Mockery::close();
}
Expand Down Expand Up @@ -2086,7 +2086,7 @@ public function testWetherMockWithInterfaceOnlyCanNotImplementNonExistingMethods
public function testCountWithBecauseExceptionMessage()
{
$this->expectException(InvalidCountException::class);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageRegex(
'/Method foo\(<Any Arguments>\) from Mockery_[\d]+ should be called' . PHP_EOL . ' ' .
'exactly 1 times but called 0 times. Because We like foo/'
);
Expand Down

0 comments on commit f24033d

Please sign in to comment.