Skip to content

Commit 9b06f97

Browse files
Merge branch '4.4' into 5.1
* 4.4: [Debug] fix test consistently use same types for strict comparisons [PhpUnitBridge] Skip internal classes in CoverageListenerTrait [VarExporter] unserialize() might throw an Exception on php 8. [ErrorHandler] Parse "x not found" errors correctly on php 8. Prevent parsing invalid octal digits as octal numbers remove unnecessary check for existing request [DI] fix ContainerBuilder on PHP8 [Console] Make sure $maxAttempts is an int or null. [VarDumper] Fix caster for invalid SplFileInfo objects on php 8. [Intl] Skip test cases that produce a TypeError on php 8. [PhpUnitBridge] Adjust output parsing for PHPUnit 9.3. [PhpUnitBridge] CoverageListenerTrait update for PHPUnit 8.5/9.x add bosnian (bs) translation [Debug] Parse "x not found" errors correctly on php 8.
2 parents e4f40da + d7d0be8 commit 9b06f97

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Legacy/CoverageListenerTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ private function addCoversForDocBlockInsideRegistry($test, $covers)
107107
$symbolAnnotations = new \ReflectionProperty($docBlock, 'symbolAnnotations');
108108
$symbolAnnotations->setAccessible(true);
109109

110+
// Exclude internal classes; PHPUnit 9.1+ is picky about tests covering, say, a \RuntimeException
111+
$covers = array_filter($covers, function ($class) {
112+
$reflector = new ReflectionClass($class);
113+
114+
return $reflector->isUserDefined();
115+
});
116+
110117
$symbolAnnotations->setValue($docBlock, array_replace($docBlock->symbolAnnotations(), [
111118
'covers' => $covers,
112119
]));

Tests/CoverageListenerTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ public function test()
2727
$dir = __DIR__.'/../Tests/Fixtures/coverage';
2828
$phpunit = $_SERVER['argv'][0];
2929

30-
exec("$php $phpunit -c $dir/phpunit-without-listener.xml.dist $dir/tests/ --coverage-text 2> /dev/null", $output);
30+
exec("$php $phpunit -c $dir/phpunit-without-listener.xml.dist $dir/tests/ --coverage-text --colors=never 2> /dev/null", $output);
3131
$output = implode("\n", $output);
32-
$this->assertStringContainsString('FooCov', $output);
32+
$this->assertMatchesRegularExpression('/FooCov\n\s*Methods:\s+100.00%[^\n]+Lines:\s+100.00%/', $output);
3333

34-
exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text 2> /dev/null", $output);
34+
exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text --colors=never 2> /dev/null", $output);
3535
$output = implode("\n", $output);
36-
$this->assertStringNotContainsString('FooCov', $output);
36+
37+
if (false === strpos($output, 'FooCov')) {
38+
$this->addToAssertionCount(1);
39+
} else {
40+
$this->assertMatchesRegularExpression('/FooCov\n\s*Methods:\s+0.00%[^\n]+Lines:\s+0.00%/', $output);
41+
}
42+
3743
$this->assertStringContainsString("SutNotFoundTest::test\nCould not find the tested class.", $output);
3844
$this->assertStringNotContainsString("CoversTest::test\nCould not find the tested class.", $output);
3945
$this->assertStringNotContainsString("CoversDefaultClassTest::test\nCould not find the tested class.", $output);

0 commit comments

Comments
 (0)