Skip to content

Commit f9f3d9d

Browse files
committed
Fixes PHPUnit 8.2 compatibility
1 parent 1b30d6e commit f9f3d9d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

autoload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class_alias(
77
);
88
}
99

10-
if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class)) {
10+
if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class)
11+
&& interface_exists(\PHPUnit\Framework\MockObject\Invocation::class)
12+
) {
1113
class_alias(
1214
\PHPUnit_Framework_MockObject_Invocation::class,
1315
\PHPUnit\Framework\MockObject\Invocation::class

classes/DefaultArgumentRemoverReturnTypes.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ public function invoked(Invocation $invocation)
2929
*/
3030
public function matches(Invocation $invocation) : bool
3131
{
32-
if ($invocation instanceof Invocation\StaticInvocation) {
33-
$this->removeDefaultArguments($invocation);
32+
$iClass = class_exists(Invocation::class);
33+
34+
if ($invocation instanceof Invocation\StaticInvocation
35+
|| $iClass
36+
) {
37+
$this->removeDefaultArguments(
38+
$invocation,
39+
$iClass ? Invocation::class : Invocation\StaticInvocation::class
40+
);
3441
} else {
3542
MockFunctionGenerator::removeDefaultArguments($invocation->parameters);
3643
}
@@ -64,12 +71,12 @@ public function toString() : string
6471
*
6572
* @SuppressWarnings(PHPMD)
6673
*/
67-
private function removeDefaultArguments(Invocation\StaticInvocation $invocation)
74+
private function removeDefaultArguments(Invocation $invocation, string $class)
6875
{
6976
$remover = function () {
7077
MockFunctionGenerator::removeDefaultArguments($this->parameters);
7178
};
7279

73-
$remover->bindTo($invocation, Invocation\StaticInvocation::class)();
80+
$remover->bindTo($invocation, $class)();
7481
}
7582
}

tests/MockObjectProxyTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace phpmock\phpunit;
44

5-
use PHPUnit\Framework\MockObject\Matcher\MethodName;
6-
use PHPUnit\Framework\MockObject\Stub\MatcherCollection;
7-
use PHPUnit\Framework\TestCase;
85
use phpmock\integration\MockDelegateFunctionBuilder;
96
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
7+
use PHPUnit\Framework\MockObject\ConfigurableMethod;
108
use PHPUnit\Framework\MockObject\Matcher\Invocation;
9+
use PHPUnit\Framework\MockObject\Matcher\MethodName;
1110
use PHPUnit\Framework\MockObject\MockObject;
11+
use PHPUnit\Framework\MockObject\Stub\MatcherCollection;
12+
use PHPUnit\Framework\TestCase;
13+
use SebastianBergmann\Type\Type;
1214

1315
/**
1416
* Tests MockObjectProxyTest.
@@ -31,10 +33,17 @@ public function testExpects()
3133
{
3234
$matcher = $this->getMockBuilder(Invocation::class)->getMock();
3335

36+
$methods = class_exists(ConfigurableMethod::class)
37+
? new ConfigurableMethod(
38+
MockDelegateFunctionBuilder::METHOD,
39+
$this->prophesize(Type::class)->reveal()
40+
)
41+
: [MockDelegateFunctionBuilder::METHOD];
42+
3443
$invocationMocker = new InvocationMocker(
3544
$this->prophesize(MatcherCollection::class)->reveal(),
3645
$this->prophesize(Invocation::class)->reveal(),
37-
[MockDelegateFunctionBuilder::METHOD]
46+
$methods
3847
);
3948

4049
$prophecy = $this->prophesize(MockObject::class);

0 commit comments

Comments
 (0)