[PhpUnitBridge] CoverageListenerTrait update for PHPUnit 8.5/9.x
This commit is contained in:
parent
9460894ae2
commit
99c98bd716
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP 5.3 compatible trait-like shared implementation.
|
* PHP 5.3 compatible trait-like shared implementation.
|
||||||
@ -70,9 +71,6 @@ class CoverageListenerTrait
|
|||||||
$testClass = \PHPUnit_Util_Test::class;
|
$testClass = \PHPUnit_Util_Test::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = new \ReflectionProperty($testClass, 'annotationCache');
|
|
||||||
$r->setAccessible(true);
|
|
||||||
|
|
||||||
$covers = $sutFqcn;
|
$covers = $sutFqcn;
|
||||||
if (!\is_array($sutFqcn)) {
|
if (!\is_array($sutFqcn)) {
|
||||||
$covers = array($sutFqcn);
|
$covers = array($sutFqcn);
|
||||||
@ -82,6 +80,20 @@ class CoverageListenerTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (class_exists(Registry::class)) {
|
||||||
|
$this->addCoversForDocBlockInsideRegistry($test, $covers);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addCoversForClassToAnnotationCache($testClass, $test, $covers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addCoversForClassToAnnotationCache($testClass, $test, $covers)
|
||||||
|
{
|
||||||
|
$r = new \ReflectionProperty($testClass, 'annotationCache');
|
||||||
|
$r->setAccessible(true);
|
||||||
|
|
||||||
$cache = $r->getValue();
|
$cache = $r->getValue();
|
||||||
$cache = array_replace_recursive($cache, array(
|
$cache = array_replace_recursive($cache, array(
|
||||||
\get_class($test) => array(
|
\get_class($test) => array(
|
||||||
@ -91,6 +103,18 @@ class CoverageListenerTrait
|
|||||||
$r->setValue($testClass, $cache);
|
$r->setValue($testClass, $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(), array(
|
||||||
|
'covers' => $covers,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
private function findSutFqcn($test)
|
private function findSutFqcn($test)
|
||||||
{
|
{
|
||||||
if ($this->sutFqcnResolver) {
|
if ($this->sutFqcnResolver) {
|
||||||
|
Reference in New Issue
Block a user