Skip to content

Commit

Permalink
[PhpUnitBridge] Enhance CoverageListenerTests
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lyrixx committed Mar 14, 2024
1 parent 20d5453 commit d928c0d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
44 changes: 28 additions & 16 deletions src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
Expand Up @@ -17,29 +17,17 @@ class CoverageListenerTest extends TestCase
{
public function test()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test cannot be run on Windows.');
}

exec('type phpdbg 2> /dev/null', $output, $returnCode);

if (0 === $returnCode) {
$php = 'phpdbg -qrr';
} else {
exec('php --ri xdebug -d zend_extension=xdebug.so 2> /dev/null', $output, $returnCode);
if (0 !== $returnCode) {
$this->markTestSkipped('Xdebug is required to run this test.');
}
$php = 'php -d zend_extension=xdebug.so';
}

$dir = __DIR__.'/../Tests/Fixtures/coverage';
$phpunit = $_SERVER['argv'][0];

$php = $this->findCoverageDriver();

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

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

Expand All @@ -54,4 +42,28 @@ public function test()
$this->assertStringNotContainsString("CoversDefaultClassTest::test\nCould not find the tested class.", $output);
$this->assertStringNotContainsString("CoversNothingTest::test\nCould not find the tested class.", $output);
}

private function findCoverageDriver(): string
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test cannot be run on Windows.');
}

exec('php --ri xdebug -d zend_extension=xdebug 2> /dev/null', $output, $returnCode);
if (0 === $returnCode) {
return 'php -d zend_extension=xdebug';
}

exec('php --ri pcov -d zend_extension=pcov 2> /dev/null', $output, $returnCode);
if (0 === $returnCode) {
return 'php -d zend_extension=pcov';
}

exec('type phpdbg 2> /dev/null', $output, $returnCode);
if (0 === $returnCode) {
return 'phpdbg -qrr';
}

$this->markTestSkipped('Xdebug or pvoc is required to run this test.');
}
}
@@ -1,30 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Fixtures/coverage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener">
<arguments>
<null/>
<null />
<boolean>true</boolean>
</arguments>
</listener>
Expand Down
@@ -1,23 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Fixtures/coverage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>

0 comments on commit d928c0d

Please sign in to comment.