diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php index 362a0f8fa5d..394d5eaf279 100644 --- a/src/Framework/MockObject/Generator.php +++ b/src/Framework/MockObject/Generator.php @@ -974,7 +974,7 @@ private function generateMockClassDeclaration(array $mockClassName, bool $isInte private function canMockMethod(\ReflectionMethod $method): bool { - return !($method->isConstructor() || $method->isFinal() || $method->isPrivate() || $this->isMethodNameBlacklisted($method->getName())); + return !($this->isConstructor($method) || $method->isFinal() || $method->isPrivate() || $this->isMethodNameBlacklisted($method->getName())); } private function isMethodNameBlacklisted(string $name): bool @@ -992,4 +992,20 @@ private function getTemplate(string $template): \Text_Template return self::$templates[$filename]; } + + /** + * @see https://github.com/sebastianbergmann/phpunit/issues/4139#issuecomment-605409765 + */ + private function isConstructor(\ReflectionMethod $method): bool + { + $methodName = \strtolower($method->getName()); + + if ($methodName === '__construct') { + return true; + } + + $className = \strtolower($method->getDeclaringClass()->getName()); + + return $methodName === $className; + } }