diff --git a/src/Plugins/Tia/Graph.php b/src/Plugins/Tia/Graph.php index 51ff1c02..207db7c7 100644 --- a/src/Plugins/Tia/Graph.php +++ b/src/Plugins/Tia/Graph.php @@ -643,7 +643,7 @@ final class Graph array $handledBlade, array &$affectedSet, ): void { - $unknownToGraph = $unparseableMigrations; + $watchedPaths = $unparseableMigrations; foreach ($nonMigrationPaths as $rel) { if (isset($preciselyHandledPages[$rel])) { @@ -660,14 +660,16 @@ final class Graph continue; } - $unknownToGraph[] = $rel; + $watchedPaths[] = $rel; + } elseif ($this->isFrameworkBootPath($rel)) { + $watchedPaths[] = $rel; } } /** @var WatchPatterns $watchPatterns */ $watchPatterns = Container::getInstance()->get(WatchPatterns::class); - $dirs = $watchPatterns->matchedDirectories($this->projectRoot, $unknownToGraph); + $dirs = $watchPatterns->matchedDirectories($this->projectRoot, $watchedPaths); $allTestFiles = array_keys($this->edges); foreach ($watchPatterns->testsUnderDirectories($dirs, $allTestFiles) as $testFile) { @@ -1174,6 +1176,11 @@ final class Graph $this->jsFileToComponents = $out; } + private function isFrameworkBootPath(string $rel): bool + { + return preg_match('#^(config/.+|bootstrap/[^/]+)\.php$#', $rel) === 1; + } + private function isMigrationPath(string $rel): bool { return str_starts_with($rel, 'database/migrations/') && str_ends_with($rel, '.php'); diff --git a/src/Plugins/Tia/WatchDefaults/Laravel.php b/src/Plugins/Tia/WatchDefaults/Laravel.php index e0bf6ac3..5e16cde9 100644 --- a/src/Plugins/Tia/WatchDefaults/Laravel.php +++ b/src/Plugins/Tia/WatchDefaults/Laravel.php @@ -23,6 +23,9 @@ final readonly class Laravel implements WatchDefault return [ 'database/migrations/**/*.php' => [$testPath], + 'config/**/*.php' => [$testPath], + 'bootstrap/*.php' => [$testPath], + 'storage/fixtures/**/*' => [$testPath], 'app/** !*.php' => [$testPath], diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 69e61bd4..26b6a2c4 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1983,6 +1983,12 @@ ✓ markKnownTestFiles() → it makes a test file with no edges known ✓ markKnownTestFiles() → it does not clobber edges of an already-known test file ✓ markKnownTestFiles() → it ignores paths outside the project root + ✓ Laravel boot files → it applies the watch patterns to a boot file that the graph links to one test only with ('config/app.php') + ✓ Laravel boot files → it applies the watch patterns to a boot file that the graph links to one test only with ('config/services/mail.php') + ✓ Laravel boot files → it applies the watch patterns to a boot file that the graph links to one test only with ('bootstrap/providers.php') + ✓ Laravel boot files → it keeps the recorded edges of a boot file that no pattern watches + ✓ Laravel boot files → it does not treat the framework cache as a boot file + ✓ Laravel boot files → it watches the config and bootstrap files in the Laravel defaults ✓ clearResults() → it drops the results of the fallback branch too ✓ branch baseline over the fallback → it reads results written after an earlier read @@ -2366,4 +2372,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, 37 skipped, 1683 passed (3728 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1689 passed (3737 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Tia/Graph.php b/tests/Unit/Plugins/Tia/Graph.php index 8447b5da..ed56d830 100644 --- a/tests/Unit/Plugins/Tia/Graph.php +++ b/tests/Unit/Plugins/Tia/Graph.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Pest\Plugins\Tia\Graph; +use Pest\Plugins\Tia\WatchDefaults\Laravel; use Pest\Plugins\Tia\WatchPatterns; use Pest\Support\Container; use PHPUnit\Framework\TestStatus\TestStatus; @@ -313,6 +314,68 @@ describe('markKnownTestFiles()', function (): void { }); }); +describe('Laravel boot files', function (): void { + beforeEach(function (): void { + $this->projectRoot = sys_get_temp_dir().'/pest-tia-boot-'.bin2hex(random_bytes(4)); + + foreach (['config/app.php', 'config/services/mail.php', 'bootstrap/providers.php', 'bootstrap/cache/config.php', 'app/Other.php'] as $file) { + @mkdir(dirname($this->projectRoot.'/'.$file), 0755, true); + file_put_contents($this->projectRoot.'/'.$file, "watchPatterns = new WatchPatterns; + Container::getInstance()->add(WatchPatterns::class, $this->watchPatterns); + + $this->graph = new Graph($this->projectRoot); + + foreach (['config/app.php', 'config/services/mail.php', 'bootstrap/providers.php', 'bootstrap/cache/config.php'] as $file) { + $this->graph->link('tests/Feature/FirstInWorkerTest.php', $file); + } + + $this->graph->link('tests/Feature/OtherTest.php', 'app/Other.php'); + }); + + afterEach(function (): void { + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($this->projectRoot, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST, + ); + + foreach ($files as $file) { + assert($file instanceof SplFileInfo); + + $file->isDir() ? @rmdir($file->getPathname()) : @unlink($file->getPathname()); + } + + @rmdir($this->projectRoot); + + Container::getInstance()->add(WatchPatterns::class, new WatchPatterns); + }); + + it('applies the watch patterns to a boot file that the graph links to one test only', function (string $bootFile): void { + $this->watchPatterns->add(['config/**/*.php' => 'tests', 'bootstrap/*.php' => 'tests']); + + expect($this->graph->affected([$bootFile])) + ->toEqualCanonicalizing(['tests/Feature/FirstInWorkerTest.php', 'tests/Feature/OtherTest.php']); + })->with(['config/app.php', 'config/services/mail.php', 'bootstrap/providers.php']); + + it('keeps the recorded edges of a boot file that no pattern watches', function (): void { + expect($this->graph->affected(['config/app.php']))->toBe(['tests/Feature/FirstInWorkerTest.php']); + }); + + it('does not treat the framework cache as a boot file', function (): void { + $this->watchPatterns->add(['bootstrap/**' => 'tests']); + + expect($this->graph->affected(['bootstrap/cache/config.php']))->toBe(['tests/Feature/FirstInWorkerTest.php']); + }); + + it('watches the config and bootstrap files in the Laravel defaults', function (): void { + expect(new Laravel()->defaults('/project', 'tests')) + ->toHaveKey('config/**/*.php', ['tests']) + ->toHaveKey('bootstrap/*.php', ['tests']); + }); +}); + describe('clearResults()', function (): void { it('drops the results of the fallback branch too', function (): void { $graph = new Graph(sys_get_temp_dir()); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 1c2eac32..21436de7 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -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, 29 skipped, 1654 passed (3650 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1660 passed (3659 assertions)'; expect($output) ->toContain("Tests: {$expected}")