8000 [PhpUnitBridge] Adjust output parsing of CoverageListenerTrait for PHPUnit 9.3 by derrabus · Pull Request #38071 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PhpUnitBridge] Adjust output parsing of CoverageListenerTrait for PHPUnit 9.3 #38071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[PhpUnitBridge] CoverageListenerTrait update for PHPUnit 8.5/9.x
  • Loading branch information
sanmai authored and derrabus committed Sep 5, 2020
commit 99c98bd716497ef70d198e264524bb62b2342a43
30 changes: 27 additions & 3 deletions src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Warning;
use PHPUnit\Util\Annotation\Registry;

/**
* PHP 5.3 compatible trait-like shared implementation.
Expand Down Expand Up @@ -70,9 +71,6 @@ public function startTest($test)
$testClass = \PHPUnit_Util_Test::class;
}

$r = new \ReflectionProperty($testClass, 'annotationCache');
$r->setAccessible(true);

$covers = $sutFqcn;
if (!\is_array($sutFqcn)) {
$covers = array($sutFqcn);
Expand All @@ -82,6 +80,20 @@ public function startTest($test)
}
}

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 = array_replace_recursive($cache, array(
\get_class($test) => array(
Expand All @@ -91,6 +103,18 @@ public function startTest($test)
$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)
{
if ($this->sutFqcnResolver) {
Expand Down
0