mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
feat: convert namespace-style arguments to file paths in pest binary (#1705)
* feat: convert namespace-style arguments to file paths in pest binary * test: allow running a single test using its namespace * fix: preserve namespace filters when converting arguments * test: update success snapshot for namespace filters * fix: convert namespace after retry flag --------- Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -129,6 +129,60 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
}
|
||||
}
|
||||
|
||||
$optionsWithSeparateValue = [
|
||||
'-c', '-d', '--atleast-version', '--bootstrap', '--cache-directory', '--columns', '--configuration',
|
||||
'--coverage-filter', '--coverage-clover', '--coverage-cobertura', '--coverage-crap4j', '--coverage-html',
|
||||
'--coverage-jsonl', '--coverage-openclover', '--coverage-php', '--coverage-xml', '--default-time-limit',
|
||||
'--diff-context', '--exclude-group', '--filter', '--exclude-filter', '--generate-baseline', '--use-baseline',
|
||||
'--group', '--covers', '--uses', '--requires-php-extension', '--include-path', '--list-tests-xml',
|
||||
'--log-junit', '--log-otr', '--log-teamcity', '--order-by', '--random-order-seed', '--repeat',
|
||||
'--timeout', '--testdox-html', '--testdox-text', '--test-suffix', '--testsuite', '--exclude-testsuite',
|
||||
'--test-files-file', '--test-id-filter-file', '--run-test-id', '--log-events-text',
|
||||
'--log-events-verbose-text', '--extension',
|
||||
];
|
||||
|
||||
$isOptionValue = false;
|
||||
|
||||
// Convert namespace-style arguments (e.g. Tests\Unit\TestName) to file paths.
|
||||
foreach ($arguments as $key => $value) {
|
||||
if ($isOptionValue) {
|
||||
$isOptionValue = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_starts_with($value, '-')) {
|
||||
$isOptionValue = in_array($value, $optionsWithSeparateValue, true);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! str_contains($value, '\\')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = str_replace('\\', DIRECTORY_SEPARATOR, $value);
|
||||
|
||||
if (! str_ends_with($path, '.php')) {
|
||||
$path .= '.php';
|
||||
}
|
||||
|
||||
if (file_exists($path)) {
|
||||
$arguments[$key] = $path;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try lowercasing the first directory segment (e.g. Tests -> tests).
|
||||
$segments = explode(DIRECTORY_SEPARATOR, $path);
|
||||
$segments[0] = lcfirst($segments[0]);
|
||||
$lowercasedPath = implode(DIRECTORY_SEPARATOR, $segments);
|
||||
|
||||
if (file_exists($lowercasedPath)) {
|
||||
$arguments[$key] = $lowercasedPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Used when Pest is required using composer.
|
||||
$autoloadPath = $GLOBALS['_composer_autoload_path'] ?? dirname(__DIR__, 3).'/autoload.php';
|
||||
|
||||
|
||||
@@ -2536,6 +2536,9 @@
|
||||
PASS Tests\Visual\SingleTestOrDirectory
|
||||
✓ allows to run a single test
|
||||
✓ allows to run a directory
|
||||
✓ allows to run a single test using its namespace
|
||||
✓ keeps namespace filters unchanged
|
||||
✓ converts a namespace after the retry flag
|
||||
✓ it disable decorating printer when colors is set to never
|
||||
|
||||
WARN Tests\Visual\Success
|
||||
@@ -2566,4 +2569,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, 38 skipped, 1860 passed (4277 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1863 passed (4281 assertions)
|
||||
@@ -30,6 +30,44 @@ test('allows to run a directory', function () use ($run, $snapshot): void {
|
||||
expect($run('tests/Fixtures/DirectoryWithTests'))->toContain($snapshot('allows-to-run-a-directory'));
|
||||
})->skipOnWindows();
|
||||
|
||||
test('allows to run a single test using its namespace', function () use ($run, $snapshot): void {
|
||||
expect($run('Tests\\Fixtures\\DirectoryWithTests\\ExampleTest'))->toContain($snapshot('allows-to-run-a-single-test'));
|
||||
})->skipOnWindows();
|
||||
|
||||
test('keeps namespace filters unchanged', function () use ($snapshot): void {
|
||||
$process = new Process([
|
||||
'php',
|
||||
'bin/pest',
|
||||
'tests/Fixtures/DirectoryWithTests',
|
||||
'--filter',
|
||||
'Tests\\\\Fixtures\\\\DirectoryWithTests\\\\ExampleTest',
|
||||
'--colors=never',
|
||||
], dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
expect(removeAnsiEscapeSequences($process->getOutput()))->toContain($snapshot('allows-to-run-a-single-test'));
|
||||
})->skipOnWindows();
|
||||
|
||||
test('converts a namespace after the retry flag', function () use ($snapshot): void {
|
||||
$process = new Process([
|
||||
'php',
|
||||
'bin/pest',
|
||||
'--retry',
|
||||
'Tests\\Fixtures\\DirectoryWithTests\\ExampleTest',
|
||||
'--colors=never',
|
||||
], dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and(removeAnsiEscapeSequences($process->getOutput()))->toContain($snapshot('allows-to-run-a-single-test'));
|
||||
})->skipOnWindows();
|
||||
|
||||
it('disable decorating printer when colors is set to never', function () use ($snapshot): void {
|
||||
$process = new Process([
|
||||
'php',
|
||||
|
||||
Reference in New Issue
Block a user