mirror of
https://github.com/pestphp/pest.git
synced 2026-12-06 07:42:17 +01:00
fix(tia): re-run every test when a Laravel config or bootstrap file changes (#1926)
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1689 passed (3737 assertions)
|
||||
@@ -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, "<?php\n\nreturn [];\n");
|
||||
}
|
||||
|
||||
$this->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());
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user