diff --git a/src/Rules/PHPUnit/MockMethodCallRule.php b/src/Rules/PHPUnit/MockMethodCallRule.php index d8bcd8a..b4592d3 100644 --- a/src/Rules/PHPUnit/MockMethodCallRule.php +++ b/src/Rules/PHPUnit/MockMethodCallRule.php @@ -52,6 +52,12 @@ public function processNode(Node $node, Scope $scope): array return $class !== MockObject::class; }); + // `MockBuilder::setMethods` and `MockBuilder::addMethods` are not supported by this rule + // so since a lot of the usage are with `stdClass`, we silent the error + if (\implode('&', $mockClass) === 'stdClass') { + return []; + } + return [ sprintf( 'Trying to mock an undefined method %s() on class %s.', diff --git a/tests/Rules/PHPUnit/MockMethodCallRuleTest.php b/tests/Rules/PHPUnit/MockMethodCallRuleTest.php index cd42678..6ebd833 100644 --- a/tests/Rules/PHPUnit/MockMethodCallRuleTest.php +++ b/tests/Rules/PHPUnit/MockMethodCallRuleTest.php @@ -26,6 +26,10 @@ public function testRule(): void 'Trying to mock an undefined method doBadThing() on class MockMethodCall\Bar.', 20, ], + [ + 'Trying to mock an undefined method doBadThing() on class MockMethodCall\Bar.', + 31, + ], ]); } diff --git a/tests/Rules/PHPUnit/data/mock-method-call.php b/tests/Rules/PHPUnit/data/mock-method-call.php index cbe5942..efee3ad 100644 --- a/tests/Rules/PHPUnit/data/mock-method-call.php +++ b/tests/Rules/PHPUnit/data/mock-method-call.php @@ -26,6 +26,16 @@ public function testWithAnotherObject() $bar->method('doBadThing'); } + public function testWithMockBuilder() + { + $this->getMockBuilder(Bar::class)->getMock()->method('doBadThing'); + } + + public function testWhenAddingMethodToStdClass() + { + $this->getMockBuilder(\stdClass::class)->setMethods(['doBadThing'])->getMock()->method('doBadThing'); + } + } class Bar {