[PhpUnitBridge] CoverageListenerTrait update for PHPUnit 8.5/9.x
This commit is contained in:
parent
067dc2ddbb
commit
5f83811002
@ -13,6 +13,7 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Warning;
|
||||
use PHPUnit\Util\Annotation\Registry;
|
||||
use PHPUnit\Util\Test;
|
||||
|
||||
/**
|
||||
@ -66,9 +67,6 @@ class CoverageListenerTrait
|
||||
return;
|
||||
}
|
||||
|
||||
$r = new \ReflectionProperty(Test::class, 'annotationCache');
|
||||
$r->setAccessible(true);
|
||||
|
||||
$covers = $sutFqcn;
|
||||
if (!\is_array($sutFqcn)) {
|
||||
$covers = [$sutFqcn];
|
||||
@ -78,15 +76,42 @@ class CoverageListenerTrait
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists(Registry::class)) {
|
||||
$this->addCoversForDocBlockInsideRegistry($test, $covers);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addCoversForClassToAnnotationCache($test, $covers);
|
||||
}
|
||||
|
||||
private function addCoversForClassToAnnotationCache($test, $covers)
|
||||
{
|
||||
$r = new \ReflectionProperty(Test::class, 'annotationCache');
|
||||
$r->setAccessible(true);
|
||||
|
||||
$cache = $r->getValue();
|
||||
$cache = array_replace_recursive($cache, [
|
||||
\get_class($test) => [
|
||||
'covers' => $covers,
|
||||
],
|
||||
]);
|
||||
|
||||
$r->setValue(Test::class, $cache);
|
||||
}
|
||||
|
||||
private function addCoversForDocBlockInsideRegistry($test, $covers)
|
||||
{
|
||||
$docBlock = Registry::getInstance()->forClassName(\get_class($test));
|
||||
|
||||
$symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations');
|
||||
$symbolAnnotations->setAccessible(true);
|
||||
|
||||
$symbolAnnotations->setValue($docBlock, array_replace($docBlock->symbolAnnotations(), [
|
||||
'covers' => $covers,
|
||||
]));
|
||||
}
|
||||
|
||||
private function findSutFqcn($test)
|
||||
{
|
||||
if ($this->sutFqcnResolver) {
|
||||
|
Reference in New Issue
Block a user