This commit is contained in:
nuno maduro
2026-07-18 02:28:29 +01:00
parent 820fa08313
commit 1ef680c75d
7 changed files with 166 additions and 9 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
use Pest\Plugins\Tia\Graph;
describe('markKnownTestFiles()', function (): void {
it('makes a test file with no edges known', function (): void {
$graph = new Graph(sys_get_temp_dir());
expect($graph->knowsTest('tests/Unit/ExampleTest.php'))->toBeFalse();
$graph->markKnownTestFiles(['tests/Unit/ExampleTest.php']);
expect($graph->knowsTest('tests/Unit/ExampleTest.php'))->toBeTrue();
});
it('does not clobber edges of an already-known test file', function (): void {
$graph = new Graph(sys_get_temp_dir());
$graph->link('tests/Feature/UserTest.php', 'app/Models/User.php');
$graph->markKnownTestFiles(['tests/Feature/UserTest.php']);
// The pre-existing edge survives — the test still depends on the source file.
$affected = $graph->affected(['app/Models/User.php']);
expect($affected)->toContain('tests/Feature/UserTest.php');
});
it('ignores paths outside the project root', function (): void {
$graph = new Graph(sys_get_temp_dir());
$graph->markKnownTestFiles(['/somewhere/else/tests/FooTest.php']);
expect($graph->knowsTest('/somewhere/else/tests/FooTest.php'))->toBeFalse();
});
});
+72
View File
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
use Pest\Plugins\Tia\TestPaths;
describe('isTestFile()', function (): void {
it('matches a standard test file under a configured directory', function (): void {
$paths = new TestPaths(
directories: ['tests/Unit', 'tests/Feature'],
files: [],
suffixes: ['Test.php'],
);
expect($paths->isTestFile('tests/Unit/ExampleTest.php'))->toBeTrue()
->and($paths->isTestFile('tests/Feature/UserTest.php'))->toBeTrue();
});
it('does not match a non-test file that shares the directory', function (): void {
$paths = new TestPaths(
directories: ['tests/Unit'],
files: [],
suffixes: ['Test.php'],
);
expect($paths->isTestFile('tests/Unit/Helper.php'))->toBeFalse();
});
it('does not match files outside the configured directories', function (): void {
$paths = new TestPaths(
directories: ['tests/Unit'],
files: [],
suffixes: ['Test.php'],
);
expect($paths->isTestFile('app/Models/UserTest.php'))->toBeFalse();
});
it('matches an explicitly listed file', function (): void {
$paths = new TestPaths(
directories: [],
files: ['tests/Pest.php'],
suffixes: ['Test.php'],
);
expect($paths->isTestFile('tests/Pest.php'))->toBeTrue();
});
it('honours a bare .php suffix', function (): void {
$paths = new TestPaths(
directories: ['tests'],
files: [],
suffixes: ['.php'],
);
expect($paths->isTestFile('tests/Unit/ExampleTest.php'))->toBeTrue()
->and($paths->isTestFile('tests/Unit/Helper.php'))->toBeTrue();
});
// Regression: a suffix of "Test.php" must match "ExampleTest.php". A previous
// normalisation prepended a dot (".Test.php"), which matched nothing and left
// edited tests looking unchanged to TIA, replaying stale results.
it('does not require a dot before the suffix', function (): void {
$paths = new TestPaths(
directories: ['tests/Unit'],
files: [],
suffixes: ['.Test.php'],
);
expect($paths->isTestFile('tests/Unit/ExampleTest.php'))->toBeFalse();
});
});