fix(tia): fingerprint the generated configuration like the restarter does (#2065)

* fix(tia): fingerprint the generated configuration like the restarter does

* test(tia): pass one configuration option per call

---------

Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
Jhon Farias
2026-11-23 10:57:13 +01:00
committed by GitHub
parent 8c87eefebf
commit 4c886b16d1
7 changed files with 104 additions and 6 deletions
+5
View File
@@ -42,6 +42,11 @@ final class Configuration implements HandlesArguments, Terminable
return $this->pushArgument((string) realpath($this->fromGeneratedConfigurationFile()), $arguments);
}
public function generatedConfigurationPath(): ?string
{
return $this->generatedConfiguration['path'] ?? null;
}
private function fromGeneratedConfigurationFile(): string
{
$directory = getcwd();
+3 -1
View File
@@ -475,7 +475,9 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument
exit(0);
}
$this->configuration = ConfigurationFile::fromArguments($arguments);
$configurationPlugin = Container::getInstance()->get(Configuration::class);
assert($configurationPlugin instanceof Configuration);
$this->configuration = ConfigurationFile::fromArguments($arguments, $configurationPlugin->generatedConfigurationPath());
$isWorker = Parallel::isWorker();
$recordingGlobal = $isWorker && (string) Parallel::getGlobal(self::RECORDING_GLOBAL) === '1';
+5 -1
View File
@@ -26,7 +26,7 @@ final readonly class ConfigurationFile
/**
* @param array<int, string> $arguments
*/
public static function fromArguments(array $arguments): self
public static function fromArguments(array $arguments, ?string $generatedPath = null): self
{
try {
$configuration = new Builder(EventFacade::emitter())->fromParameters(self::configurationParameters($arguments));
@@ -41,6 +41,10 @@ final readonly class ConfigurationFile
$file = new XmlConfigurationFileFinder()->find($configuration);
$path = $file === false ? false : realpath($file);
if ($path !== false && $generatedPath !== null && $path === realpath($generatedPath)) {
return self::projectDefault();
}
return new self($path === false ? null : $path, false);
}
+5 -1
View File
@@ -1987,6 +1987,10 @@
✓ it tells an identical copy under another name apart from the original
✓ it resolves a configuration directory the way PHPUnit does
✓ it gives a run with --no-configuration its own fingerprint
✓ it fingerprints the configuration Pest generates the way the Xdebug restarter does with dataset "first name"
✓ it fingerprints the configuration Pest generates the way the Xdebug restarter does with dataset "fallback name"
✓ it fingerprints the configuration Pest generates the way the Xdebug restarter does with dataset "random name"
✓ it fingerprints an explicit configuration apart from the one Pest generates
PASS Tests\Unit\Plugins\Tia\ContentHash
✓ of() → it returns false when file does not exist
@@ -2662,4 +2666,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, 39 skipped, 1951 passed (4419 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 1955 passed (4433 assertions)
@@ -100,3 +100,34 @@ test('an identical copy of the configuration file under another name does not re
->and($result->replayed())->toBe(0, $result->describe())
->and($result->tally())->toContain(Project::TOTAL_TESTS.' passed');
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
function removeConfiguration(Project $project): void
{
$project->git()->run(['rm', '--quiet', 'phpunit.xml']);
$project->write('.gitignore', file_get_contents($project->path('.gitignore'))."/.pest*.xml\n");
$project->git()->commit('use the configuration Pest generates');
$project->write('vendor/pestphp/pest/.temp/.gitkeep', '');
}
test('a project without a configuration file replays the graph', function (array $arguments): void {
$project = Project::make('master');
removeConfiguration($project);
$project->seed('master');
$result = $project->pest('--tia', ...$arguments);
expect($result->exitCode)->toBe(0, $result->describe())
->and($result->replayed())->toBe(Project::TOTAL_TESTS, $result->describe());
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
test('a leftover generated configuration file does not discard the graph', function (array $arguments): void {
$project = Project::make('master');
removeConfiguration($project);
$project->seed('master');
$project->write('.pest.xml', (string) file_get_contents($project->path('vendor/pestphp/pest/resources/base-phpunit.xml')));
$replayed = $project->pest('--tia', ...$arguments);
expect($replayed->exitCode)->toBe(0, $replayed->describe())
->and($replayed->replayed())->toBe(Project::TOTAL_TESTS, $replayed->describe());
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
+54 -2
View File
@@ -2,6 +2,7 @@
declare(strict_types=1);
use Pest\Plugins\Configuration;
use Pest\Plugins\Tia\ConfigurationFile;
beforeEach(function (): void {
@@ -14,8 +15,12 @@ beforeEach(function (): void {
});
afterEach(function (): void {
@unlink($this->projectRoot.'/phpunit.xml');
@unlink($this->projectRoot.'/phpunit.copy.xml');
foreach (['phpunit.xml', 'phpunit.copy.xml'] as $file) {
if (is_file($this->projectRoot.'/'.$file)) {
unlink($this->projectRoot.'/'.$file);
}
}
@rmdir($this->projectRoot);
});
@@ -40,3 +45,50 @@ it('gives a run with --no-configuration its own fingerprint', function (): void
->toBe('none')
->not->toBe(ConfigurationFile::projectDefault()->fingerprint($this->projectRoot));
});
it('fingerprints the configuration Pest generates the way the Xdebug restarter does', function (array $leftovers): void {
unlink($this->projectRoot.'/phpunit.xml');
foreach ($leftovers as $leftover) {
file_put_contents($this->projectRoot.'/'.$leftover, '');
}
$workingDirectory = (string) getcwd();
chdir($this->projectRoot);
$configuration = new Configuration;
try {
$arguments = $configuration->handleArguments(['pest', '--tia']);
$generatedPath = $configuration->generatedConfigurationPath();
expect($generatedPath)->toBeString()
->and(basename((string) $generatedPath))->not->toBeIn($leftovers)
->and(ConfigurationFile::fromArguments($arguments, $generatedPath)->fingerprint($this->projectRoot))
->toBeNull()
->toBe(ConfigurationFile::fromArguments(['pest', '--tia'])->fingerprint($this->projectRoot));
} finally {
$configuration->terminate();
chdir($workingDirectory);
foreach ($leftovers as $leftover) {
unlink($this->projectRoot.'/'.$leftover);
}
}
})->with([
'first name' => [[]],
'fallback name' => [['.pest.xml']],
'random name' => [['.pest.xml', '.pest-fallback.xml']],
]);
it('fingerprints an explicit configuration apart from the one Pest generates', function (): void {
$generatedPath = $this->projectRoot.'/.pest.xml';
file_put_contents($generatedPath, '');
try {
expect(ConfigurationFile::fromArguments(['-c'.$this->projectRoot.'/phpunit.copy.xml'], $generatedPath)->fingerprint($this->projectRoot))
->toBe(ConfigurationFile::at($this->projectRoot.'/phpunit.copy.xml')->fingerprint($this->projectRoot))
->not->toBe(ConfigurationFile::fromArguments(['--configuration', $generatedPath], $generatedPath)->fingerprint($this->projectRoot));
} finally {
unlink($generatedPath);
}
});
+1 -1
View File
@@ -21,7 +21,7 @@ test('parallel', function () use ($run): void {
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
$profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile');
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1824 passed (3894 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1828 passed (3908 assertions)';
expect($output)
->toContain("Tests: {$expected}")