mirror of
https://github.com/pestphp/pest.git
synced 2026-12-04 15:05:09 +01:00
fdc57f77b7
* 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>
82 lines
3.0 KiB
PHP
82 lines
3.0 KiB
PHP
<?php
|
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
$run = function (string $target, $decorated = false): ?string {
|
|
$process = new Process(['php', 'bin/pest', $target, '--colors=always'], dirname(__DIR__, 2),
|
|
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
|
);
|
|
|
|
$process->run();
|
|
|
|
return $decorated ? $process->getOutput() : removeAnsiEscapeSequences($process->getOutput());
|
|
};
|
|
|
|
$snapshot = function ($name): string|false {
|
|
$testsPath = dirname(__DIR__);
|
|
|
|
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
|
$testsPath,
|
|
'.snapshots',
|
|
"$name.txt",
|
|
]));
|
|
};
|
|
|
|
test('allows to run a single test', function () use ($run, $snapshot): void {
|
|
expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'))->toContain($snapshot('allows-to-run-a-single-test'));
|
|
})->skipOnWindows();
|
|
|
|
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',
|
|
'./bin/pest',
|
|
'--colors=never',
|
|
'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
|
], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1']);
|
|
$process->run();
|
|
$output = $process->getOutput();
|
|
expect($output)->toContain($snapshot('disable-decorating-printer'));
|
|
})->skipOnWindows();
|