Skip to content

Commit

Permalink
Add workaround for ReflectionMethod::isConstructor() issue described in
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 28, 2020
1 parent fb668be commit 477798f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Framework/MockObject/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}

0 comments on commit 477798f

Please sign in to comment.