Skip to content

Commit c9c8071

Browse files
committed
fix(tia): suppress PHPUnit XML coverage during recording
When phpunit.xml has <coverage> and <source> sections, PHPUnit auto-initializes its code coverage driver which takes over xdebug's coverage APIs. TIA's recorder then gets empty data from xdebug_get_code_coverage(), resulting in zero recorded edges and no graph being saved. Inject --no-coverage into the arguments when TIA enters its own recording mode (not piggybacking on an explicit coverage report). This tells PHPUnit to ignore XML-configured coverage reports, leaving xdebug free for TIA's per-test recording. Having <coverage> and <source> in phpunit.xml is standard for any project that generates coverage reports. Without this fix, users must manually pass --no-coverage alongside --tia, which is an unnecessary footgun.
1 parent bf7c6b3 commit c9c8071

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/Plugins/Tia.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,10 @@ private function enterRecordMode(array $arguments): array
12341234
return $arguments;
12351235
}
12361236

1237+
if (! $this->piggybackCoverage && ! in_array('--no-coverage', $arguments, true)) {
1238+
$arguments[] = '--no-coverage';
1239+
}
1240+
12371241
if (Parallel::isEnabled()) {
12381242
$this->purgeWorkerPartials();
12391243

tests/Features/Tia/CoveragePiggyback.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,44 @@
3939
->and($graph['files'])->toContain('app/Calculator.php');
4040
})->skipOnWindows();
4141

42+
test('xml-configured coverage does not prevent tia recording', function (): void {
43+
$project = Project::make('master');
44+
45+
$project->write('phpunit.xml', <<<'XML'
46+
<?xml version="1.0" encoding="UTF-8"?>
47+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
49+
bootstrap="vendor/autoload.php"
50+
cacheDirectory=".phpunit.cache"
51+
colors="true"
52+
failOnRisky="true"
53+
failOnWarning="false"
54+
>
55+
<testsuites>
56+
<testsuite name="default">
57+
<directory suffix="Test.php">./tests</directory>
58+
</testsuite>
59+
</testsuites>
60+
<coverage>
61+
<report>
62+
<clover outputFile="coverage/clover.xml" />
63+
</report>
64+
</coverage>
65+
<source>
66+
<include>
67+
<directory suffix=".php">./app</directory>
68+
</include>
69+
</source>
70+
</phpunit>
71+
XML);
72+
73+
$result = $project->pest('--tia');
74+
75+
expect($result->exitCode)->toBe(0)
76+
->and($project->graphExists())->toBeTrue()
77+
->and(array_keys($project->graph()['edges']))->toEqualCanonicalizing(array_keys(Project::EDGES));
78+
})->skipOnWindows();
79+
4280
test('a coverage report leaves the edges of an existing graph alone', function (): void {
4381
$project = Project::make('master');
4482
$project->seed('master');

0 commit comments

Comments
 (0)