Skip to content

Commit 4cc5c6c

Browse files
committed
MockMethodCallRule - do not report for empty $mockClasses
1 parent 34ee324 commit 4cc5c6c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Rules/PHPUnit/MockMethodCallRule.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ public function processNode(Node $node, Scope $scope): array
7676
continue;
7777
}
7878

79+
$classNames = $mockedClassObject->getObjectClassNames();
80+
if (count($classNames) === 0) {
81+
continue;
82+
}
83+
7984
$errors[] = sprintf(
8085
'Trying to mock an undefined method %s() on class %s.',
8186
$method,
82-
implode('|', $mockedClassObject->getObjectClassNames())
87+
implode('|', $classNames)
8388
);
8489
}
8590

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

+15
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,18 @@ public function method(string $string)
5656
return $string;
5757
}
5858
};
59+
60+
final class FinalFoo
61+
{
62+
63+
}
64+
65+
class FinalFooTest extends \PHPUnit\Framework\TestCase
66+
{
67+
68+
public function testMockFinalClass()
69+
{
70+
$this->createMock(FinalFoo::class)->method('doFoo');
71+
}
72+
73+
}

0 commit comments

Comments
 (0)