Skip to content

Commit 4b17a23

Browse files
committed
Fix MockMethodCallRule
1 parent abc2da9 commit 4b17a23

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Rules/PHPUnit/MockMethodCallRule.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@ public function processNode(Node $node, Scope $scope): array
5656
)
5757
&& !$type->hasMethod($method)->yes()
5858
) {
59-
$mockClass = array_filter($type->getObjectClassNames(), static function (string $class): bool {
59+
$mockClasses = array_filter($type->getObjectClassNames(), static function (string $class): bool {
6060
return $class !== MockObject::class && $class !== Stub::class;
6161
});
62+
if (count($mockClasses) === 0) {
63+
continue;
64+
}
6265

6366
$errors[] = sprintf(
6467
'Trying to mock an undefined method %s() on class %s.',
6568
$method,
66-
implode('&', $mockClass)
69+
implode('&', $mockClasses)
6770
);
71+
continue;
6872
}
6973

7074
$mockedClassObject = $type->getTemplateType(InvocationMocker::class, 'TMockedClass');

tests/Rules/PHPUnit/data/mock-method-call.php

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function testBadMethodOnStub()
3636
$this->createStub(Bar::class)->method('doBadThing');
3737
}
3838

39+
public function testMockObject(\PHPUnit\Framework\MockObject\MockObject $mock)
40+
{
41+
$mock->method('doFoo');
42+
}
43+
3944
}
4045

4146
class Bar {

0 commit comments

Comments
 (0)