mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
fix(tia): match test files under wildcard suite directories (#1980)
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
@@ -35,10 +35,12 @@ final readonly class TestPaths
|
||||
|
||||
foreach ($configuration->testSuite() as $suite) {
|
||||
foreach ($suite->directories() as $directory) {
|
||||
$rel = self::toRelative($directory->path(), $projectRoot);
|
||||
foreach (self::expandWildcards($directory->path()) as $path) {
|
||||
$rel = self::toRelative($path, $projectRoot);
|
||||
|
||||
if ($rel !== null) {
|
||||
$directories[] = $rel;
|
||||
if ($rel !== null) {
|
||||
$directories[] = $rel;
|
||||
}
|
||||
}
|
||||
|
||||
$suffixes[] = $directory->suffix();
|
||||
@@ -104,6 +106,18 @@ final readonly class TestPaths
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private static function expandWildcards(string $path): array
|
||||
{
|
||||
if (! str_contains($path, '*')) {
|
||||
return [$path];
|
||||
}
|
||||
|
||||
return glob($path, GLOB_ONLYDIR) ?: [$path];
|
||||
}
|
||||
|
||||
private static function toRelative(string $value, string $projectRoot): ?string
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
test('a new test file under a wildcard suite directory is selected', function (array $arguments): void {
|
||||
$project = Project::make('master', overlay: 'wildcard-suite');
|
||||
$project->seed('master');
|
||||
|
||||
$project->write('tests/Unit/BrandNewTest.php', <<<'PHP'
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
test('brand new thing', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
PHP);
|
||||
|
||||
$result = $project->pest('--tia', '--filtered', ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->output)->not->toContain('No affected tests found')
|
||||
->and($result->affected())->toBe(1, $result->describe())
|
||||
->and($result->tally())->toContain('1 passed');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
|
||||
|
||||
test('a test file moved under a wildcard suite directory is selected at its new path', function (array $arguments): void {
|
||||
$project = Project::make('master', overlay: 'wildcard-suite');
|
||||
$project->seed('master');
|
||||
|
||||
$project->git()->run(['mv', 'tests/Unit/GreeterTest.php', 'tests/Feature/GreeterTest.php']);
|
||||
|
||||
$result = $project->pest('--tia', '--filtered', ...$arguments);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->output)->not->toContain('No affected tests found')
|
||||
->and($result->affected())->toBe(2, $result->describe())
|
||||
->and($result->tally())->toContain('2 passed');
|
||||
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
colors="true"
|
||||
failOnRisky="true"
|
||||
failOnWarning="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory suffix="Test.php">./tests/*</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<source>
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user