Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4b17a23

Browse files
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 5 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /