mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Allow help and version before the test suite is initialized (#2051)
Co-authored-by: haranishi <223786623+haranishi@users.noreply.github.com> Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -36,7 +36,7 @@ final class BootFiles implements Bootstrapper
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
if ($this->runningInit()) {
|
||||
if ($this->hasCliOption('--init')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ final class BootFiles implements Bootstrapper
|
||||
$testsPath = $rootPath.DIRECTORY_SEPARATOR.testDirectory();
|
||||
|
||||
if (! is_dir($testsPath)) {
|
||||
if ($this->hasCliOption('--help', '--version')) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FatalException(sprintf('The test directory [%s] does not exist.', $testsPath));
|
||||
}
|
||||
|
||||
@@ -69,7 +73,7 @@ final class BootFiles implements Bootstrapper
|
||||
$this->bootDatasets($testsPath);
|
||||
}
|
||||
|
||||
private function runningInit(): bool
|
||||
private function hasCliOption(string ...$options): bool
|
||||
{
|
||||
$arguments = $_SERVER['argv'] ?? null;
|
||||
|
||||
@@ -78,7 +82,7 @@ final class BootFiles implements Bootstrapper
|
||||
}
|
||||
|
||||
/** @var array<int, string> $arguments */
|
||||
return $this->hasArgument('--init', $arguments);
|
||||
return array_any($options, fn (string $option): bool => $this->hasArgument($option, $arguments));
|
||||
}
|
||||
|
||||
private function load(string $filename): void
|
||||
|
||||
@@ -2559,9 +2559,11 @@
|
||||
|
||||
WARN Tests\Visual\Version
|
||||
- visual snapshot of help command output
|
||||
✓ prints information when the tests directory is missing with dataset "help"
|
||||
✓ prints information when the tests directory is missing with dataset "version"
|
||||
|
||||
PASS Testsexternal\Features\Expect\toMatchSnapshot
|
||||
✓ 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, 1858 passed (4273 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1860 passed (4277 assertions)
|
||||
@@ -63,7 +63,7 @@ test('a missing tests directory does not crash while resolving tia state', funct
|
||||
$root = makeInitProject();
|
||||
|
||||
try {
|
||||
$process = runInitProject($root, '--version');
|
||||
$process = runInitProject($root);
|
||||
|
||||
expect($process->getExitCode())->not->toBe(0)
|
||||
->and($process->getOutput())->toContain('does not exist')
|
||||
@@ -110,10 +110,6 @@ require {$autoload};
|
||||
|
||||
\$arguments = array_slice(\$argv, 1);
|
||||
|
||||
if (\$arguments === []) {
|
||||
\$arguments = ['--version'];
|
||||
}
|
||||
|
||||
\$GLOBALS['_composer_bin_dir'] = getcwd().'/vendor/bin';
|
||||
|
||||
\$_SERVER['argv'] = ['pest', ...\$arguments];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
test('visual snapshot of help command output', function (): void {
|
||||
$output = function (): ?string {
|
||||
@@ -13,3 +14,22 @@ test('visual snapshot of help command output', function (): void {
|
||||
|
||||
expect($output())->toMatchSnapshot();
|
||||
})->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'));
|
||||
|
||||
test('prints information when the tests directory is missing', function (string $option, string $expected): void {
|
||||
$project = Project::withoutGit();
|
||||
|
||||
try {
|
||||
rename($project->path('tests'), $project->path('fixtures'));
|
||||
unlink($project->path('phpunit.xml'));
|
||||
|
||||
$result = $project->pest($option);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->output)->toContain($expected);
|
||||
} finally {
|
||||
Project::destroyAll();
|
||||
}
|
||||
})->with([
|
||||
'help' => ['--help', '--init'],
|
||||
'version' => ['--version', 'Pest Testing Framework'],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user