Skip to content

Commit

Permalink
Fix MockMethodCallRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 21, 2023
1 parent abc2da9 commit 4b17a23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Rules/PHPUnit/MockMethodCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ public function processNode(Node $node, Scope $scope): array
)
&& !$type->hasMethod($method)->yes()
) {
$mockClass = array_filter($type->getObjectClassNames(), static function (string $class): bool {
$mockClasses = array_filter($type->getObjectClassNames(), static function (string $class): bool {
return $class !== MockObject::class && $class !== Stub::class;
});
if (count($mockClasses) === 0) {
continue;
}

$errors[] = sprintf(
'Trying to mock an undefined method %s() on class %s.',
$method,
implode('&', $mockClass)
implode('&', $mockClasses)
);
continue;
}

$mockedClassObject = $type->getTemplateType(InvocationMocker::class, 'TMockedClass');
Expand Down
5 changes: 5 additions & 0 deletions tests/Rules/PHPUnit/data/mock-method-call.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function testBadMethodOnStub()
$this->createStub(Bar::class)->method('doBadThing');
}

public function testMockObject(\PHPUnit\Framework\MockObject\MockObject $mock)
{
$mock->method('doFoo');
}

}

class Bar {
Expand Down

0 comments on commit 4b17a23

Please sign in to comment.