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..13189fa5f 100644 --- a/library/Mockery/Adapter/Phpunit/MockeryTestCase.php +++ b/library/Mockery/Adapter/Phpunit/MockeryTestCase.php @@ -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); + } } 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..50833c99e 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->assertMatchesRegEx( '/Mockery_(\d+)__demeter_([0-9a-f]+)_foo/', Mockery::getContainer()->getKeyOfDemeterMockFor('foo', get_class($m)) ); @@ -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(); } diff --git a/tests/Mockery/ExpectationTest.php b/tests/Mockery/ExpectationTest.php index 438156d31..1852f86ed 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(); } @@ -2086,7 +2086,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/' );