Skip to content

Commit e49f84b

Browse files
minor #54283 [PhpUnitBridge] Enhance CoverageListenerTests (lyrixx)
This PR was merged into the 7.1 branch. Discussion ---------- [PhpUnitBridge] Enhance CoverageListenerTests | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT The test were broken on my laptop, so I dig it a bit and: * Add support support for pvoc * Change priority of driver, it's now xdebug > pcov > phpdbg (reflects more real usages) * Update deprecated phpunit.xml.dist configuration * Ensure the $output buffer is empty before running sub-tests * open php bug report because phpdbg segfault, see php/php-src#13707 Commits ------- 4f49fd3 [PhpUnitBridge] Enhance CoverageListenerTests
2 parents 682aff8 + 4f49fd3 commit e49f84b

File tree

3 files changed

+51
-46
lines changed

3 files changed

+51
-46
lines changed

src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,17 @@ class CoverageListenerTest extends TestCase
1717
{
1818
public function test()
1919
{
20-
if ('\\' === \DIRECTORY_SEPARATOR) {
21-
$this->markTestSkipped('This test cannot be run on Windows.');
22-
}
23-
24-
exec('type phpdbg 2> /dev/null', $output, $returnCode);
25-
26-
if (0 === $returnCode) {
27-
$php = 'phpdbg -qrr';
28-
} else {
29-
exec('php --ri xdebug -d zend_extension=xdebug.so 2> /dev/null', $output, $returnCode);
30-
if (0 !== $returnCode) {
31-
$this->markTestSkipped('Xdebug is required to run this test.');
32-
}
33-
$php = 'php -d zend_extension=xdebug.so';
34-
}
35-
3620
$dir = __DIR__.'/../Tests/Fixtures/coverage';
3721
$phpunit = $_SERVER['argv'][0];
3822

23+
$php = $this->findCoverageDriver();
24+
25+
$output = '';
3926
exec("$php $phpunit -c $dir/phpunit-without-listener.xml.dist $dir/tests/ --coverage-text --colors=never 2> /dev/null", $output);
4027
$output = implode("\n", $output);
4128
$this->assertMatchesRegularExpression('/FooCov\n\s*Methods:\s+100.00%[^\n]+Lines:\s+100.00%/', $output);
4229

30+
$output = '';
4331
exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text --colors=never 2> /dev/null", $output);
4432
$output = implode("\n", $output);
4533

@@ -54,4 +42,28 @@ public function test()
5442
$this->assertStringNotContainsString("CoversDefaultClassTest::test\nCould not find the tested class.", $output);
5543
$this->assertStringNotContainsString("CoversNothingTest::test\nCould not find the tested class.", $output);
5644
}
45+
46+
private function findCoverageDriver(): string
47+
{
48+
if ('\\' === \DIRECTORY_SEPARATOR) {
49+
$this->markTestSkipped('This test cannot be run on Windows.');
50+
}
51+
52+
exec('php --ri xdebug -d zend_extension=xdebug 2> /dev/null', $output, $returnCode);
53+
if (0 === $returnCode) {
54+
return 'php -d zend_extension=xdebug';
55+
}
56+
57+
exec('php --ri pcov -d zend_extension=pcov 2> /dev/null', $output, $returnCode);
58+
if (0 === $returnCode) {
59+
return 'php -d zend_extension=pcov';
60+
}
61+
62+
exec('type phpdbg 2> /dev/null', $output, $returnCode);
63+
if (0 === $returnCode) {
64+
return 'phpdbg -qrr';
65+
}
66+
67+
$this->markTestSkipped('Xdebug or pvoc is required to run this test.');
68+
}
5769
}

src/Symfony/Bridge/PhpUnit/Tests/Fixtures/coverage/phpunit-with-listener.xml.dist

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5-
backupGlobals="false"
6-
colors="true"
7-
bootstrap="tests/bootstrap.php"
8-
failOnRisky="true"
9-
failOnWarning="true"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="true"
6+
bootstrap="tests/bootstrap.php"
7+
failOnRisky="true"
8+
failOnWarning="true"
109
>
11-
10+
<coverage>
11+
<include>
12+
<directory>src</directory>
13+
</include>
14+
</coverage>
1215
<testsuites>
1316
<testsuite name="Fixtures/coverage Test Suite">
1417
<directory>tests</directory>
1518
</testsuite>
1619
</testsuites>
17-
18-
<filter>
19-
<whitelist>
20-
<directory>src</directory>
21-
</whitelist>
22-
</filter>
23-
2420
<listeners>
2521
<listener class="Symfony\Bridge\PhpUnit\CoverageListener">
2622
<arguments>
27-
<null/>
23+
<null />
2824
<boolean>true</boolean>
2925
</arguments>
3026
</listener>
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5-
backupGlobals="false"
6-
colors="true"
7-
bootstrap="tests/bootstrap.php"
8-
failOnRisky="true"
9-
failOnWarning="true"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="true"
6+
bootstrap="tests/bootstrap.php"
7+
failOnRisky="true"
8+
failOnWarning="true"
109
>
11-
10+
<coverage>
11+
<include>
12+
<directory>src</directory>
13+
</include>
14+
</coverage>
1215
<testsuites>
1316
<testsuite name="Fixtures/coverage Test Suite">
1417
<directory>tests</directory>
1518
</testsuite>
1619
</testsuites>
17-
18-
<filter>
19-
<whitelist>
20-
<directory>src</directory>
21-
</whitelist>
22-
</filter>
2320
</phpunit>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy