diff --git a/src/Plugins/Tia.php b/src/Plugins/Tia.php index be761fc7b..dfd594b87 100644 --- a/src/Plugins/Tia.php +++ b/src/Plugins/Tia.php @@ -624,7 +624,7 @@ public function terminate(): void $changedFiles = new ChangedFiles($projectRoot); $currentSha = $changedFiles->currentSha(); - $currentFingerprint = Fingerprint::compute($projectRoot); + $currentFingerprint = Fingerprint::compute($projectRoot, $this->originalArguments); if ($this->structuralFingerprintShifted($currentFingerprint)) { $this->renderBadge('WARN', 'Project files changed during the run — discarding recorded edges.'); @@ -710,7 +710,7 @@ public function addOutput(int $exitCode): int $changedFiles = new ChangedFiles($projectRoot); $currentSha = $changedFiles->currentSha(); - $currentFingerprint = Fingerprint::compute($projectRoot); + $currentFingerprint = Fingerprint::compute($projectRoot, $this->originalArguments); if ($this->structuralFingerprintShifted($currentFingerprint)) { $this->renderBadge('WARN', 'Project files changed during the run — discarding recorded edges.'); @@ -848,7 +848,7 @@ private function handleParent(array $arguments, string $projectRoot, bool $force : new TiaRequiresRemote); } - $fingerprint = Fingerprint::compute($projectRoot); + $fingerprint = Fingerprint::compute($projectRoot, $this->originalArguments); $this->startFingerprint = $fingerprint; if ($forceRebuild && ! $this->detachedHead) { diff --git a/src/Plugins/Tia/Fingerprint.php b/src/Plugins/Tia/Fingerprint.php index 39e562399..8890eb94a 100644 --- a/src/Plugins/Tia/Fingerprint.php +++ b/src/Plugins/Tia/Fingerprint.php @@ -22,19 +22,19 @@ ]; /** + * @param array $arguments * @return array{ * structural: array, * environmental: array, * } */ - public static function compute(string $projectRoot): array + public static function compute(string $projectRoot, array $arguments = []): array { return [ 'structural' => [ 'schema' => self::SCHEMA_VERSION, 'composer_lock' => self::composerLockHash($projectRoot), - 'phpunit_xml' => self::trackedHash($projectRoot, 'phpunit.xml'), - 'phpunit_xml_dist' => self::trackedHash($projectRoot, 'phpunit.xml.dist'), + 'phpunit_xml' => self::phpunitConfigurationHash($projectRoot, $arguments), 'vite_config' => self::viteConfigHash($projectRoot), 'package_lock' => self::packageLockHash($projectRoot), 'js_config' => self::jsConfigHash($projectRoot), @@ -197,6 +197,70 @@ private static function jsConfigHash(string $projectRoot): ?string return $parts === [] ? null : hash('xxh128', implode("\n", $parts)); } + /** + * @param array $arguments + */ + private static function phpunitConfigurationHash(string $projectRoot, array $arguments): ?string + { + foreach (self::configurationCandidates($projectRoot, $arguments) as $candidate) { + $hash = self::hashIfExists($candidate); + + if ($hash !== null) { + return $hash; + } + } + + return null; + } + + /** + * @param array $arguments + * @return list + */ + private static function configurationCandidates(string $projectRoot, array $arguments): array + { + $option = self::configurationOption($arguments); + + $path = $option === null ? $projectRoot : realpath($option); + + if ($path === false) { + return []; + } + + if (is_file($path)) { + return [$path]; + } + + return [ + $path.DIRECTORY_SEPARATOR.'phpunit.xml', + $path.DIRECTORY_SEPARATOR.'phpunit.xml.dist', + ]; + } + + /** + * @param array $arguments + */ + private static function configurationOption(array $arguments): ?string + { + $arguments = array_values($arguments); + + foreach ($arguments as $index => $argument) { + if ($argument === '-c' || $argument === '--configuration') { + return $arguments[$index + 1] ?? null; + } + + if (str_starts_with($argument, '--configuration=')) { + return substr($argument, strlen('--configuration=')); + } + + if (str_starts_with($argument, '-c')) { + return substr($argument, 2); + } + } + + return null; + } + private static function composerLockHash(string $projectRoot): ?string { return self::trackedHash($projectRoot, 'composer.lock'); diff --git a/src/Restarters/XdebugRestarter.php b/src/Restarters/XdebugRestarter.php index 7a4c0b395..6635be7ce 100644 --- a/src/Restarters/XdebugRestarter.php +++ b/src/Restarters/XdebugRestarter.php @@ -86,10 +86,13 @@ private function runLooksDroppable(array $arguments, string $projectRoot): bool return false; } - return $this->tiaWillReplay($projectRoot); + return $this->tiaWillReplay($projectRoot, $arguments); } - private function tiaWillReplay(string $projectRoot): bool + /** + * @param array $arguments + */ + private function tiaWillReplay(string $projectRoot, array $arguments): bool { $path = Storage::tempDir($projectRoot).DIRECTORY_SEPARATOR.Tia::KEY_GRAPH; @@ -111,7 +114,7 @@ private function tiaWillReplay(string $projectRoot): bool return Fingerprint::structuralMatches( $graph->fingerprint(), - Fingerprint::compute($projectRoot), + Fingerprint::compute($projectRoot, $arguments), ); } } diff --git a/tests/Features/Tia.php b/tests/Features/Tia.php index edba5911b..d8a648166 100644 --- a/tests/Features/Tia.php +++ b/tests/Features/Tia.php @@ -13,6 +13,7 @@ $projectRoot = dirname(__DIR__, 2); $home = sys_get_temp_dir().'/pest-tia-'.bin2hex(random_bytes(8)); $fixture = 'tests/Fixtures/Suites/TiaReplayHooks.php'; + $arguments = ['--configuration', 'tests/Fixtures/Suites/TiaReplayHooks.xml', '--tia']; mkdir($home, 0755, true); @@ -24,7 +25,7 @@ $id = fn (string $description): string => 'P\Tests\Fixtures\Suites\TiaReplayHooks::'.Str::evaluable($description); $graph = new Graph($projectRoot); - $graph->setFingerprint(Fingerprint::compute($projectRoot)); + $graph->setFingerprint(Fingerprint::compute($projectRoot, $arguments)); $graph->setRecordedAtSha($branch, $sha); $graph->setLastRunTree($branch, $changedFiles->snapshotTree($changedFiles->since($sha) ?? [])); $graph->markKnownTestFiles([$fixture]); @@ -48,7 +49,7 @@ expect($storage->write(Tia::KEY_GRAPH, (string) $json))->toBeTrue(); $process = new Process( - ['php', 'bin/pest', '--configuration', 'tests/Fixtures/Suites/TiaReplayHooks.xml', '--tia'], + ['php', 'bin/pest', ...$arguments], $projectRoot, [ 'COLLISION_PRINTER' => 'DefaultPrinter',