Compare commits

...

3 Commits

Author SHA1 Message Date
Caleb White 17d709e32b chore: rector fixes (#1898) 2026-09-04 18:33:34 +05:30
Lazizbek Ergashev 46df02dc28 fix: key Tia worker partials per process to survive batch recycling (#1782)
* fix: key Tia worker partials per process to survive batch recycling

* test(tia): refresh visual snapshots for the worker token test

---------

Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
2026-08-26 14:06:49 +05:30
Caleb White fc17365bd1 fix(tia): suppress PHPUnit XML coverage during recording (#1845)
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.
2026-08-26 01:25:57 +05:30
8 changed files with 95 additions and 18 deletions
+1 -3
View File
@@ -234,9 +234,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
$parts = explode('\\', $class);
$current = &$tree;
foreach ($parts as $part) {
if (! isset($current[$part])) {
$current[$part] = [];
}
$current[$part] ??= [];
$current = &$current[$part];
}
}
+7 -4
View File
@@ -1238,6 +1238,10 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument
return $arguments;
}
if (! $this->piggybackCoverage && ! in_array('--no-coverage', $arguments, true)) {
$arguments[] = '--no-coverage';
}
if (Parallel::isEnabled()) {
$this->purgeWorkerPartials();
@@ -1501,7 +1505,8 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument
private function workerToken(): string
{
$raw = $_SERVER['TEST_TOKEN'] ?? $_ENV['TEST_TOKEN'] ?? null;
$raw = $_SERVER['UNIQUE_TEST_TOKEN'] ?? $_ENV['UNIQUE_TEST_TOKEN']
?? $_SERVER['TEST_TOKEN'] ?? $_ENV['TEST_TOKEN'] ?? null;
$token = is_scalar($raw) ? (string) $raw : (string) getmypid();
$token = preg_replace('/[^A-Za-z0-9_-]/', '', $token);
@@ -1532,9 +1537,7 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument
foreach (['files', 'tables', 'inertia'] as $section) {
foreach ($data[$section] as $testFile => $values) {
if (! isset($merged[$section][$testFile])) {
$merged[$section][$testFile] = [];
}
$merged[$section][$testFile] ??= [];
foreach ($values as $value) {
$merged[$section][$testFile][$value] = true;
+2 -6
View File
@@ -1020,9 +1020,7 @@ final class Graph
private function ensureBaseline(string $branch): void
{
if (! isset($this->baselines[$branch])) {
$this->baselines[$branch] = ['sha' => null, 'tree' => [], 'results' => []];
}
$this->baselines[$branch] ??= ['sha' => null, 'tree' => [], 'results' => []];
}
/**
@@ -1067,9 +1065,7 @@ final class Graph
continue;
}
if (! isset($this->edges[$rel])) {
$this->edges[$rel] = [];
}
$this->edges[$rel] ??= [];
}
}
+1 -3
View File
@@ -111,9 +111,7 @@ final class Preset
*/
private function baseNamespaces(): array
{
if (self::$baseNamespaces === null) {
self::$baseNamespaces = Composer::userNamespaces();
}
self::$baseNamespaces ??= Composer::userNamespaces();
return self::$baseNamespaces;
}
+5 -1
View File
@@ -2061,6 +2061,10 @@
✓ it accepts a page directory candidate only when it matches the casing on disk with ('wrong parent')
✓ it accepts a page directory candidate only when it matches the casing on disk with ('absent')
PASS Tests\Unit\Plugins\Tia\WorkerToken
✓ prefers the per-process UNIQUE_TEST_TOKEN over the per-slot TEST_TOKEN, so two workers recycled into the same slot get different tokens
✓ falls back to TEST_TOKEN when UNIQUE_TEST_TOKEN is absent
PASS Tests\Unit\Preset
✓ preset invalid name
✓ preset → myFramework
@@ -2251,4 +2255,4 @@
✓ pass with dataset with ('my-datas-set-value')
✓ within describe → pass with dataset with ('my-datas-set-value')
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1596 passed (3481 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1598 passed (3485 assertions)
+39
View File
@@ -2,6 +2,7 @@
declare(strict_types=1);
use Pest\Support\Coverage;
use Tests\Fixtures\Tia\Project;
afterEach(function (): void {
@@ -39,6 +40,44 @@ test('a plain run after a coverage run records the whole project scope', functio
->and($graph['files'])->toContain('app/Calculator.php');
})->skipOnWindows();
test('xml-configured coverage does not prevent tia recording', function (): void {
$project = Project::make('master');
$project->write('phpunit.xml', <<<'XML_WRAP'
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
failOnRisky="true"
failOnWarning="false"
>
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<clover outputFile="coverage/clover.xml" />
</report>
</coverage>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>
XML_WRAP);
$result = $project->pest('--tia');
expect($result->exitCode)->toBe(0, $result->describe())
->and($project->graphExists())->toBeTrue()
->and(array_keys($project->graph()['edges']))->toEqualCanonicalizing(array_keys(Project::EDGES));
})->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');
test('a coverage report leaves the edges of an existing graph alone', function (): void {
$project = Project::make('master');
$project->seed('master');
+39
View File
@@ -0,0 +1,39 @@
<?php
use Pest\Plugins\Tia;
function tiaWorkerToken(): string
{
$tia = new ReflectionClass(Tia::class)->newInstanceWithoutConstructor();
return new ReflectionMethod($tia, 'workerToken')->invoke($tia);
}
beforeEach(function (): void {
unset(
$_SERVER['TEST_TOKEN'],
$_ENV['TEST_TOKEN'],
$_SERVER['UNIQUE_TEST_TOKEN'],
$_ENV['UNIQUE_TEST_TOKEN'],
);
});
test('prefers the per-process UNIQUE_TEST_TOKEN over the per-slot TEST_TOKEN, so two workers recycled into the same slot get different tokens', function (): void {
$_SERVER['TEST_TOKEN'] = '2';
$_SERVER['UNIQUE_TEST_TOKEN'] = '2_6a690d236824c';
$processA = tiaWorkerToken();
$_SERVER['UNIQUE_TEST_TOKEN'] = '2_9f31be04117a';
$processB = tiaWorkerToken();
expect($processA)->toBe('2_6a690d236824c')
->and($processB)->toBe('2_9f31be04117a')
->and($processA)->not->toBe($processB);
});
test('falls back to TEST_TOKEN when UNIQUE_TEST_TOKEN is absent', function (): void {
$_SERVER['TEST_TOKEN'] = '3';
expect(tiaWorkerToken())->toBe('3');
});
+1 -1
View File
@@ -20,7 +20,7 @@ test('parallel', function () use ($run): void {
$output = $run('--exclude-group=integration');
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1578 passed (3426 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1580 passed (3430 assertions)';
expect($output)
->toContain("Tests: {$expected}")