-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
CoverageListenerTest.php
69 lines (55 loc) · 2.47 KB
/
CoverageListenerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\PhpUnit\Tests;
use PHPUnit\Framework\TestCase;
class CoverageListenerTest extends TestCase
{
public function test()
{
$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);
if (false === strpos($output, 'FooCov')) {
$this->addToAssertionCount(1);
} else {
$this->assertMatchesRegularExpression('/FooCov\n\s*Methods:\s+0.00%[^\n]+Lines:\s+0.00%/', $output);
}
$this->assertStringContainsString("SutNotFoundTest::test\nCould not find the tested class.", $output);
$this->assertStringNotContainsString("CoversTest::test\nCould not find the tested class.", $output);
$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.');
}
}