Skip to content

Commit 99cc5ac

Browse files
Add test for --source CLI option
1 parent ddc3324 commit 99cc5ac

File tree

9 files changed

+145
-0
lines changed

9 files changed

+145
-0
lines changed

build.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@
155155
<arg value="--filter"/>
156156
<arg value="testGreetsWithName"/>
157157
</exec>
158+
159+
<exec executable="${basedir}/vendor/bin/phpunit" taskname="phpunit">
160+
<arg value="--configuration"/>
161+
<arg path="${basedir}/tests/fixture/example3/phpunit.xml"/>
162+
<arg value="--coverage-php"/>
163+
<arg path="${basedir}/tests/fixture/example3/coverage/testAdd.cov"/>
164+
<arg value="--filter"/>
165+
<arg value="testAdd"/>
166+
</exec>
158167
</target>
159168

160169
<target name="publish-phar" description="Publish PHAR on phar.phpunit.de">
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
phpcov merge --openclover /tmp/file --source /tmp/source <directory with .cov files from different base paths>
3+
--INI--
4+
xdebug.overload_var_dump=0
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
require __DIR__ . '/../../../vendor/autoload.php';
8+
9+
$covDir = sys_get_temp_dir() . '/phpcov_merge_' . uniqid();
10+
mkdir($covDir);
11+
12+
foreach (glob(__DIR__ . '/../../fixture/example/coverage/*.cov') as $f) {
13+
copy($f, $covDir . '/' . basename($f));
14+
}
15+
16+
foreach (glob(__DIR__ . '/../../fixture/example3/coverage/*.cov') as $f) {
17+
copy($f, $covDir . '/' . basename($f));
18+
}
19+
20+
$sourceDir = sys_get_temp_dir() . '/phpcov_source_' . uniqid();
21+
mkdir($sourceDir);
22+
23+
copy(__DIR__ . '/../../fixture/example/src/Greeter.php', $sourceDir . '/Greeter.php');
24+
copy(__DIR__ . '/../../fixture/example/src/autoload.php', $sourceDir . '/autoload.php');
25+
copy(__DIR__ . '/../../fixture/example3/src/Calculator.php', $sourceDir . '/Calculator.php');
26+
27+
$tmp = tempnam(sys_get_temp_dir(), __FILE__);
28+
29+
$_SERVER['argv'][1] = 'merge';
30+
$_SERVER['argv'][2] = '--openclover';
31+
$_SERVER['argv'][3] = $tmp;
32+
$_SERVER['argv'][4] = '--source';
33+
$_SERVER['argv'][5] = $sourceDir;
34+
$_SERVER['argv'][6] = $covDir;
35+
36+
var_dump((new SebastianBergmann\PHPCOV\Application)->run($_SERVER['argv']));
37+
38+
$xml = file_get_contents($tmp);
39+
40+
var_dump(str_contains($xml, 'Greeter.php'));
41+
var_dump(str_contains($xml, 'Calculator.php'));
42+
43+
$dom = new DOMDocument;
44+
var_dump($dom->loadXML($xml));
45+
var_dump($dom->documentElement->tagName);
46+
47+
unlink($tmp);
48+
49+
array_map('unlink', glob($covDir . '/*.cov'));
50+
rmdir($covDir);
51+
52+
array_map('unlink', glob($sourceDir . '/*.php'));
53+
rmdir($sourceDir);
54+
--EXPECTF--
55+
phpcov %s by Sebastian Bergmann.
56+
57+
Generating code coverage report in OpenClover XML format ... done
58+
int(0)
59+
bool(true)
60+
bool(true)
61+
bool(true)
62+
string(8) "coverage"
1 Byte
Binary file not shown.
0 Bytes
Binary file not shown.
1.13 KB
Binary file not shown.

tests/fixture/example3/phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="src/autoload.php"
5+
failOnRisky="true"
6+
failOnWarning="true">
7+
<testsuites>
8+
<testsuite name="default">
9+
<directory>tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
13+
<source>
14+
<include>
15+
<directory>src</directory>
16+
</include>
17+
</source>
18+
</phpunit>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpcov.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\PHPCOV\TestFixture;
11+
12+
final class Calculator
13+
{
14+
public function add(int $a, int $b): int
15+
{
16+
return $a + $b;
17+
}
18+
19+
public function multiply(int $a, int $b): int
20+
{
21+
return $a * $b;
22+
}
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of phpcov.
5+
*
6+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
require __DIR__ . '/Calculator.php';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpcov.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\PHPCOV\TestFixture;
11+
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\TestCase;
14+
15+
#[CoversClass(Calculator::class)]
16+
final class CalculatorTest extends TestCase
17+
{
18+
public function testAdd(): void
19+
{
20+
$this->assertSame(3, (new Calculator)->add(1, 2));
21+
}
22+
}

0 commit comments

Comments
 (0)