From a728a0e30a40f2d153a9b19c5a3e5f6771781e1a Mon Sep 17 00:00:00 2001 From: webimpress Date: Sat, 2 Feb 2019 00:22:21 +0000 Subject: [PATCH 1/4] Added PHPUnit 8 support --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index c8b6287..4da042a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,8 @@ env: - PHPUNIT_VERSION=~7.2.0 - PHPUNIT_VERSION=~7.3.0 - PHPUNIT_VERSION=~7.4.0 + - PHPUNIT_VERSION=~7.5.0 + - PHPUNIT_VERSION=~8.0.0 php: - 7.3 @@ -30,8 +32,16 @@ php: matrix: fast_finish: true exclude: + - php: 7.1 + env: PHPUNIT_VERSION=dev-master + - php: 7.1 + env: PHPUNIT_VERSION=~8.0.0 - php: 7 env: PHPUNIT_VERSION=dev-master + - php: 7 + env: PHPUNIT_VERSION=~8.0.0 + - php: 7 + env: PHPUNIT_VERSION=~7.5.0 - php: 7 env: PHPUNIT_VERSION=~7.4.0 - php: 7 From bb84d59cf54a204f6c17f925d60a6b8c5505c14c Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 4 Mar 2019 21:16:32 +0000 Subject: [PATCH 2/4] Updated composer.json to allow PHPUnit 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5a93b9d..cfc2c6a 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require": { "php": ">=7", - "phpunit/phpunit": "^6 || ^7", + "phpunit/phpunit": "^6 || ^7 || ^8", "php-mock/php-mock-integration": "^2" }, "archive": { From 16e630cdd601792235cc09134143f596757f9227 Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 4 Mar 2019 21:17:20 +0000 Subject: [PATCH 3/4] Updated tests to work with PHPUnit 8 InvocationMocker is marked as final and cannot be mocked anymore. --- autoload.php | 14 ++++++++++++++ tests/MockObjectProxyTest.php | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/autoload.php b/autoload.php index 06fc33b..67c8e93 100644 --- a/autoload.php +++ b/autoload.php @@ -28,6 +28,20 @@ class_alias( ); } +if (! class_exists(\PHPUnit\Framework\MockObject\Matcher\MethodName::class)) { + class_alias( + \PHPUnit_Framework_MockObject_Matcher_MethodName::class, + \PHPUnit\Framework\MockObject\Matcher\MethodName::class + ); +} + +if (! interface_exists(\PHPUnit\Framework\MockObject\Stub\MatcherCollection::class)) { + class_alias( + \PHPUnit_Framework_MockObject_Stub_MatcherCollection::class, + \PHPUnit\Framework\MockObject\Stub\MatcherCollection::class + ); +} + if (! class_exists(\PHPUnit\Framework\BaseTestListener::class)) { include __DIR__ . '/compatibility/BaseTestListener.php'; class_alias( diff --git a/tests/MockObjectProxyTest.php b/tests/MockObjectProxyTest.php index 5587d0f..ad4a0f3 100644 --- a/tests/MockObjectProxyTest.php +++ b/tests/MockObjectProxyTest.php @@ -2,6 +2,8 @@ namespace phpmock\phpunit; +use PHPUnit\Framework\MockObject\Matcher\MethodName; +use PHPUnit\Framework\MockObject\Stub\MatcherCollection; use PHPUnit\Framework\TestCase; use phpmock\integration\MockDelegateFunctionBuilder; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; @@ -29,9 +31,11 @@ public function testExpects() { $matcher = $this->getMockBuilder(Invocation::class)->getMock(); - $invocationMocker = $this->getMockBuilder(InvocationMocker::class)->disableOriginalConstructor()->getMock(); - $invocationMocker->expects($this->once())->method("method") - ->with(MockDelegateFunctionBuilder::METHOD)->willReturn($invocationMocker); + $invocationMocker = new InvocationMocker( + $this->prophesize(MatcherCollection::class)->reveal(), + $this->prophesize(Invocation::class)->reveal(), + [MockDelegateFunctionBuilder::METHOD] + ); $prophecy = $this->prophesize(MockObject::class); $prophecy->expects($matcher)->willReturn($invocationMocker); @@ -41,6 +45,11 @@ public function testExpects() $result = $proxy->expects($matcher); $this->assertEquals($invocationMocker, $result); + + $this->assertSame( + (new MethodName(MockDelegateFunctionBuilder::METHOD))->toString(), + ($invocationMocker->getMatcher()->methodNameMatcher ?? $invocationMocker->getMatcher()->getMethodNameMatcher())->toString() + ); } /** From a25b10bf265bc10bc0a3c9e76b4346d85b4a5bdd Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 4 Mar 2019 21:29:33 +0000 Subject: [PATCH 4/4] CS fix - wrap long lines --- tests/MockObjectProxyTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/MockObjectProxyTest.php b/tests/MockObjectProxyTest.php index ad4a0f3..8f28d1c 100644 --- a/tests/MockObjectProxyTest.php +++ b/tests/MockObjectProxyTest.php @@ -48,7 +48,8 @@ public function testExpects() $this->assertSame( (new MethodName(MockDelegateFunctionBuilder::METHOD))->toString(), - ($invocationMocker->getMatcher()->methodNameMatcher ?? $invocationMocker->getMatcher()->getMethodNameMatcher())->toString() + ($invocationMocker->getMatcher()->methodNameMatcher + ?? $invocationMocker->getMatcher()->getMethodNameMatcher())->toString() ); }