From 1b30d6e6a66ab55562d4229501c44549c6f233db Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 7 Jun 2019 10:44:56 +0100 Subject: [PATCH 1/4] Updated Travis CI configuration Runs tests against PHPUnit 8.2 Adds PHP 7.4-snapshot Removes HHVM support --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f0d9d8e..9ccc839 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,25 +22,30 @@ env: - PHPUNIT_VERSION=~7.5.0 - PHPUNIT_VERSION=~8.0.0 - PHPUNIT_VERSION=~8.1.0 + - PHPUNIT_VERSION=~8.2.0 php: + - 7.4-snapshot - 7.3 - 7.2 - 7.1 - 7 - - hhvm matrix: fast_finish: true exclude: - php: 7.1 env: PHPUNIT_VERSION=dev-master + - php: 7.1 + env: PHPUNIT_VERSION=~8.2.0 - php: 7.1 env: PHPUNIT_VERSION=~8.1.0 - php: 7.1 env: PHPUNIT_VERSION=~8.0.0 - php: 7 env: PHPUNIT_VERSION=dev-master + - php: 7 + env: PHPUNIT_VERSION=~8.2.0 - php: 7 env: PHPUNIT_VERSION=~8.1.0 - php: 7 @@ -58,7 +63,7 @@ matrix: - php: 7 env: PHPUNIT_VERSION=~7.0.0 allow_failures: - - php: hhvm + - php: 7.4-snapshot - env: PHPUNIT_VERSION=dev-master install: From f9f3d9dd5220ceae39eb7c37cad9c61638845b46 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 7 Jun 2019 12:29:55 +0100 Subject: [PATCH 2/4] Fixes PHPUnit 8.2 compatibility --- autoload.php | 4 +++- classes/DefaultArgumentRemoverReturnTypes.php | 15 +++++++++++---- tests/MockObjectProxyTest.php | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/autoload.php b/autoload.php index 9de6a88..72867bb 100644 --- a/autoload.php +++ b/autoload.php @@ -7,7 +7,9 @@ class_alias( ); } -if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class)) { +if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class) + && interface_exists(\PHPUnit\Framework\MockObject\Invocation::class) +) { class_alias( \PHPUnit_Framework_MockObject_Invocation::class, \PHPUnit\Framework\MockObject\Invocation::class diff --git a/classes/DefaultArgumentRemoverReturnTypes.php b/classes/DefaultArgumentRemoverReturnTypes.php index 1a8adf5..bfdadfe 100644 --- a/classes/DefaultArgumentRemoverReturnTypes.php +++ b/classes/DefaultArgumentRemoverReturnTypes.php @@ -29,8 +29,15 @@ public function invoked(Invocation $invocation) */ public function matches(Invocation $invocation) : bool { - if ($invocation instanceof Invocation\StaticInvocation) { - $this->removeDefaultArguments($invocation); + $iClass = class_exists(Invocation::class); + + if ($invocation instanceof Invocation\StaticInvocation + || $iClass + ) { + $this->removeDefaultArguments( + $invocation, + $iClass ? Invocation::class : Invocation\StaticInvocation::class + ); } else { MockFunctionGenerator::removeDefaultArguments($invocation->parameters); } @@ -64,12 +71,12 @@ public function toString() : string * * @SuppressWarnings(PHPMD) */ - private function removeDefaultArguments(Invocation\StaticInvocation $invocation) + private function removeDefaultArguments(Invocation $invocation, string $class) { $remover = function () { MockFunctionGenerator::removeDefaultArguments($this->parameters); }; - $remover->bindTo($invocation, Invocation\StaticInvocation::class)(); + $remover->bindTo($invocation, $class)(); } } diff --git a/tests/MockObjectProxyTest.php b/tests/MockObjectProxyTest.php index 317b763..244ab67 100644 --- a/tests/MockObjectProxyTest.php +++ b/tests/MockObjectProxyTest.php @@ -2,13 +2,15 @@ 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; +use PHPUnit\Framework\MockObject\ConfigurableMethod; use PHPUnit\Framework\MockObject\Matcher\Invocation; +use PHPUnit\Framework\MockObject\Matcher\MethodName; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub\MatcherCollection; +use PHPUnit\Framework\TestCase; +use SebastianBergmann\Type\Type; /** * Tests MockObjectProxyTest. @@ -31,10 +33,17 @@ public function testExpects() { $matcher = $this->getMockBuilder(Invocation::class)->getMock(); + $methods = class_exists(ConfigurableMethod::class) + ? new ConfigurableMethod( + MockDelegateFunctionBuilder::METHOD, + $this->prophesize(Type::class)->reveal() + ) + : [MockDelegateFunctionBuilder::METHOD]; + $invocationMocker = new InvocationMocker( $this->prophesize(MatcherCollection::class)->reveal(), $this->prophesize(Invocation::class)->reveal(), - [MockDelegateFunctionBuilder::METHOD] + $methods ); $prophecy = $this->prophesize(MockObject::class); From 7f6e19a99e4f5fe8513f7ed947b9f3da787bf55e Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 7 Jun 2019 12:31:51 +0100 Subject: [PATCH 3/4] Fixes Travis CI configuration - reorder PHPUnit versions that we run the latests first - 7.4snapshot instead of 7.4-snapshot --- .travis.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ccc839..0f53079 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,24 +8,24 @@ cache: env: - PHPUNIT_VERSION=dev-master - - PHPUNIT_VERSION=~6.0.0 - - PHPUNIT_VERSION=~6.1.0 - - PHPUNIT_VERSION=~6.2.0 - - PHPUNIT_VERSION=~6.3.0 - - PHPUNIT_VERSION=~6.4.0 - - PHPUNIT_VERSION=~6.5.0 - - PHPUNIT_VERSION=~7.0.0 - - PHPUNIT_VERSION=~7.1.0 - - 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 - - PHPUNIT_VERSION=~8.1.0 - PHPUNIT_VERSION=~8.2.0 + - PHPUNIT_VERSION=~8.1.0 + - PHPUNIT_VERSION=~8.0.0 + - PHPUNIT_VERSION=~7.5.0 + - PHPUNIT_VERSION=~7.4.0 + - PHPUNIT_VERSION=~7.3.0 + - PHPUNIT_VERSION=~7.2.0 + - PHPUNIT_VERSION=~7.1.0 + - PHPUNIT_VERSION=~7.0.0 + - PHPUNIT_VERSION=~6.5.0 + - PHPUNIT_VERSION=~6.4.0 + - PHPUNIT_VERSION=~6.3.0 + - PHPUNIT_VERSION=~6.2.0 + - PHPUNIT_VERSION=~6.1.0 + - PHPUNIT_VERSION=~6.0.0 php: - - 7.4-snapshot + - 7.4snapshot - 7.3 - 7.2 - 7.1 @@ -63,7 +63,7 @@ matrix: - php: 7 env: PHPUNIT_VERSION=~7.0.0 allow_failures: - - php: 7.4-snapshot + - php: 7.4snapshot - env: PHPUNIT_VERSION=dev-master install: From 8ef45f319edd6b9c268b5857e0c12f219e333dbb Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 7 Jun 2019 13:00:37 +0100 Subject: [PATCH 4/4] Fixed typo in autoloader --- autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload.php b/autoload.php index 72867bb..5eb1a7e 100644 --- a/autoload.php +++ b/autoload.php @@ -8,7 +8,7 @@ class_alias( } if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class) - && interface_exists(\PHPUnit\Framework\MockObject\Invocation::class) + && interface_exists(\PHPUnit_Framework_MockObject_Invocation::class) ) { class_alias( \PHPUnit_Framework_MockObject_Invocation::class,