[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\TestCase;
|
||||||
use PHPUnit\Framework\Warning;
|
use PHPUnit\Framework\Warning;
|
||||||
|
use PHPUnit\Util\Annotation\Registry;
|
||||||
use PHPUnit\Util\Test;
|
use PHPUnit\Util\Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,9 +67,6 @@ class CoverageListenerTrait
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = new \ReflectionProperty(Test::class, 'annotationCache');
|
|
||||||
$r->setAccessible(true);
|
|
||||||
|
|
||||||
$covers = $sutFqcn;
|
$covers = $sutFqcn;
|
||||||
if (!\is_array($sutFqcn)) {
|
if (!\is_array($sutFqcn)) {
|
||||||
$covers = [$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 = $r->getValue();
|
||||||
$cache = array_replace_recursive($cache, [
|
$cache = array_replace_recursive($cache, [
|
||||||
\get_class($test) => [
|
\get_class($test) => [
|
||||||
'covers' => $covers,
|
'covers' => $covers,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$r->setValue(Test::class, $cache);
|
$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)
|
private function findSutFqcn($test)
|
||||||
{
|
{
|
||||||
if ($this->sutFqcnResolver) {
|
if ($this->sutFqcnResolver) {
|
||||||
|
Reference in New Issue
Block a user