diff --git a/src/Console/Command.php b/src/Console/Command.php index 0a2f9cf2a..cfd8f0d40 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -148,5 +148,7 @@ protected function showHelp(): void $version = Container::getInstance()->get(Version::class); $version->handleArguments(['--version']); parent::showHelp(); + + (new Help($this->output))(); } } diff --git a/src/Console/Help.php b/src/Console/Help.php new file mode 100644 index 000000000..4554b728c --- /dev/null +++ b/src/Console/Help.php @@ -0,0 +1,37 @@ + */ + private const HELP_MESSAGES = [ + 'Pest Options:', + ' --init Initialise a standard Pest configuration', + ' --coverage Enable coverage and output to standard output', + ' --min= Set the minimum required coverage percentage (), and fail if not met', + ' --group= Only runs tests from the specified group(s)', + ]; + + /** @var OutputInterface */ + private $output; + + public function __construct(OutputInterface $output) + { + $this->output = $output; + } + + public function __invoke(): void + { + foreach (self::HELP_MESSAGES as $message) { + $this->output->writeln($message); + } + } +} diff --git a/tests/.snapshots/help-command.txt b/tests/.snapshots/help-command.txt new file mode 100644 index 000000000..203e8d077 --- /dev/null +++ b/tests/.snapshots/help-command.txt @@ -0,0 +1,5 @@ +Pest Options: + --init Initialise a standard Pest configuration + --coverage Enable coverage and output to standard output + --min= Set the minimum required coverage percentage (), and fail if not met + --group= Only runs tests from the specified group(s) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 06190d84d..94fbb5da3 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -348,6 +348,9 @@ ✓ it throws exception when `process isolation` is true ✓ it do not throws exception when `process isolation` is false + PASS Tests\Unit\Console\Help + ✓ it outputs the help information when --help is used + PASS Tests\Unit\Datasets ✓ it show the names of named datasets in their description @@ -374,6 +377,9 @@ PASS Tests\Unit\TestSuite ✓ it does not allow to add the same test description twice + PASS Tests\Visual\Help + ✓ visual snapshot of help command output + PASS Tests\Visual\SingleTestOrDirectory ✓ allows to run a single test ✓ allows to run a directory @@ -391,5 +397,5 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 7 skipped, 231 passed + Tests: 7 skipped, 233 passed \ No newline at end of file diff --git a/tests/Unit/Console/Help.php b/tests/Unit/Console/Help.php new file mode 100644 index 000000000..56b544870 --- /dev/null +++ b/tests/Unit/Console/Help.php @@ -0,0 +1,12 @@ +fetch())->toContain('Pest Options:'); +}); diff --git a/tests/Visual/Help.php b/tests/Visual/Help.php new file mode 100644 index 000000000..e015108f0 --- /dev/null +++ b/tests/Visual/Help.php @@ -0,0 +1,27 @@ +fetch()); + } + + $output = function () { + $process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help'])); + + $process->run(); + + return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); + }; + + expect($output())->toContain(file_get_contents($snapshot)); +})->skip(PHP_OS_FAMILY === 'Windows');