From 87527cb6d5ad44a1a3eba41de2006d90ccf96f7c Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Wed, 29 Apr 2020 14:32:14 +0300 Subject: [PATCH 1/6] Add support for PHPUnit version 9 --- composer.json | 2 +- .../Phpunit/Legacy/TestListenerTrait.php | 7 +++++- .../Adapter/Phpunit/MockeryTestCase.php | 9 ++++++++ .../Adapter/Phpunit/TestListenerTest.php | 22 ++++++++++++++++--- tests/Mockery/ContainerTest.php | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index bf0bd0e1a..f5e243c7f 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/library/Mockery/Adapter/Phpunit/Legacy/TestListenerTrait.php b/library/Mockery/Adapter/Phpunit/Legacy/TestListenerTrait.php index 02b5d0452..72d8633c1 100644 --- a/library/Mockery/Adapter/Phpunit/Legacy/TestListenerTrait.php +++ b/library/Mockery/Adapter/Phpunit/Legacy/TestListenerTrait.php @@ -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; + } } } diff --git a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php index a2129f363..fcbda803a 100644 --- a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php +++ b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php @@ -37,4 +37,13 @@ protected function mockeryTestSetUp() protected function mockeryTestTearDown() { } + + public function expectExceptionMessageRegExp($regularExpression) + { + if (method_exists(get_parent_class(), 'expectExceptionMessageRegExp')) { + return parent::expectExceptionMessageRegExp($regularExpression); + } + + return $this->expectExceptionMessageMatches($regularExpression); + } } diff --git a/tests/Mockery/Adapter/Phpunit/TestListenerTest.php b/tests/Mockery/Adapter/Phpunit/TestListenerTest.php index 7e01cf1d8..9d13abdc7 100644 --- a/tests/Mockery/Adapter/Phpunit/TestListenerTest.php +++ b/tests/Mockery/Adapter/Phpunit/TestListenerTest.php @@ -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]); + } } } diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index e63f9815b..2bcb4f7db 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -37,7 +37,7 @@ public function testGetKeyOfDemeterMockShouldReturnKeyWhenMatchingMock() { $m = mock(); $m->shouldReceive('foo->bar'); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/Mockery_(\d+)__demeter_([0-9a-f]+)_foo/', Mockery::getContainer()->getKeyOfDemeterMockFor('foo', get_class($m)) ); From 4120f625d696a97f44585635c15312d9760c434e Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Wed, 29 Apr 2020 14:41:14 +0300 Subject: [PATCH 2/6] Fix ContainerTest --- tests/Mockery/ContainerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index 2bcb4f7db..bf2d5f786 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -37,7 +37,7 @@ public function testGetKeyOfDemeterMockShouldReturnKeyWhenMatchingMock() { $m = mock(); $m->shouldReceive('foo->bar'); - $this->assertMatchesRegularExpression( + $this->expectExceptionMessageRegExp( '/Mockery_(\d+)__demeter_([0-9a-f]+)_foo/', Mockery::getContainer()->getKeyOfDemeterMockFor('foo', get_class($m)) ); From c1fb7a39094525cb12e18f37002ab4819c657ab5 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Wed, 29 Apr 2020 14:53:28 +0300 Subject: [PATCH 3/6] Fix regex assert --- library/Mockery/Adapter/Phpunit/MockeryTestCase.php | 9 +++++++++ tests/Mockery/ContainerTest.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php index fcbda803a..3c1eb9279 100644 --- a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php +++ b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php @@ -46,4 +46,13 @@ public function expectExceptionMessageRegExp($regularExpression) return $this->expectExceptionMessageMatches($regularExpression); } + + public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void + { + if (method_exists(get_parent_class(), 'assertMatchesRegularExpression')) { + parent::assertMatchesRegularExpression($pattern, $string, $message); + } + + self::assertRegExp($pattern, $string, $message); + } } diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index bf2d5f786..2bcb4f7db 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -37,7 +37,7 @@ public function testGetKeyOfDemeterMockShouldReturnKeyWhenMatchingMock() { $m = mock(); $m->shouldReceive('foo->bar'); - $this->expectExceptionMessageRegExp( + $this->assertMatchesRegularExpression( '/Mockery_(\d+)__demeter_([0-9a-f]+)_foo/', Mockery::getContainer()->getKeyOfDemeterMockFor('foo', get_class($m)) ); From 78d5c0f8c07d2d2910129b58e7e8f9b5b2708959 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Wed, 29 Apr 2020 14:56:12 +0300 Subject: [PATCH 4/6] fix --- library/Mockery/Adapter/Phpunit/MockeryTestCase.php | 2 +- tests/Mockery/ContainerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php index 3c1eb9279..932832122 100644 --- a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php +++ b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php @@ -47,7 +47,7 @@ public function expectExceptionMessageRegExp($regularExpression) return $this->expectExceptionMessageMatches($regularExpression); } - public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void + public static function assertMatchesRegEx($pattern, $string, $message = '') { if (method_exists(get_parent_class(), 'assertMatchesRegularExpression')) { parent::assertMatchesRegularExpression($pattern, $string, $message); diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index 2bcb4f7db..4e4f2a49e 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -37,7 +37,7 @@ public function testGetKeyOfDemeterMockShouldReturnKeyWhenMatchingMock() { $m = mock(); $m->shouldReceive('foo->bar'); - $this->assertMatchesRegularExpression( + $this->assertMatchesRegEx( '/Mockery_(\d+)__demeter_([0-9a-f]+)_foo/', Mockery::getContainer()->getKeyOfDemeterMockFor('foo', get_class($m)) ); From 5624da4179425af9c6f68dcb02ab1af583c256bf Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Wed, 29 Apr 2020 15:01:52 +0300 Subject: [PATCH 5/6] fix --- library/Mockery/Adapter/Phpunit/MockeryTestCase.php | 2 +- tests/Mockery/ExpectationTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php index 932832122..13189fa5f 100644 --- a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php +++ b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php @@ -38,7 +38,7 @@ protected function mockeryTestTearDown() { } - public function expectExceptionMessageRegExp($regularExpression) + public function expectExceptionMessageRegEx($regularExpression) { if (method_exists(get_parent_class(), 'expectExceptionMessageRegExp')) { return parent::expectExceptionMessageRegExp($regularExpression); diff --git a/tests/Mockery/ExpectationTest.php b/tests/Mockery/ExpectationTest.php index fc2a7a3b5..c6e626bc0 100644 --- a/tests/Mockery/ExpectationTest.php +++ b/tests/Mockery/ExpectationTest.php @@ -428,7 +428,7 @@ 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(); } @@ -436,7 +436,7 @@ public function testExpectsStringArgumentExceptionMessageDifferentiatesBetweenNu 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(); } @@ -2078,7 +2078,7 @@ public function testWetherMockWithInterfaceOnlyCanNotImplementNonExistingMethods public function testCountWithBecauseExceptionMessage() { $this->expectException(InvalidCountException::class); - $this->expectExceptionMessageRegexp( + $this->expectExceptionMessageRegex( '/Method foo\(\) from Mockery_[\d]+ should be called' . PHP_EOL . ' ' . 'exactly 1 times but called 0 times. Because We like foo/' ); From 969980f8959a8f3e510f182f52645af1cbf64be3 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Thu, 14 May 2020 11:01:49 +0300 Subject: [PATCH 6/6] fix --- tests/Mockery/ContainerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index 4e4f2a49e..50833c99e 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -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(); } @@ -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(); }