mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
Merge pull request #217 from owenvoke/feature/help
feat: add Pest options to help output
This commit is contained in:
@ -148,5 +148,7 @@ final class Command extends BaseCommand
|
|||||||
$version = Container::getInstance()->get(Version::class);
|
$version = Container::getInstance()->get(Version::class);
|
||||||
$version->handleArguments(['--version']);
|
$version->handleArguments(['--version']);
|
||||||
parent::showHelp();
|
parent::showHelp();
|
||||||
|
|
||||||
|
(new Help($this->output))();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/Console/Help.php
Normal file
37
src/Console/Help.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Console;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Help
|
||||||
|
{
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private const HELP_MESSAGES = [
|
||||||
|
'<comment>Pest Options:</comment>',
|
||||||
|
' <info>--init</info> Initialise a standard Pest configuration',
|
||||||
|
' <info>--coverage</info> Enable coverage and output to standard output',
|
||||||
|
' <info>--min=<fg=cyan><N></></info> Set the minimum required coverage percentage (<N>), and fail if not met',
|
||||||
|
' <info>--group=<fg=cyan><name></></info> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
tests/.snapshots/help-command.txt
Normal file
5
tests/.snapshots/help-command.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Pest Options:
|
||||||
|
--init Initialise a standard Pest configuration
|
||||||
|
--coverage Enable coverage and output to standard output
|
||||||
|
--min=<N> Set the minimum required coverage percentage (<N>), and fail if not met
|
||||||
|
--group=<name> Only runs tests from the specified group(s)
|
||||||
@ -348,6 +348,9 @@
|
|||||||
✓ it throws exception when `process isolation` is true
|
✓ it throws exception when `process isolation` is true
|
||||||
✓ it do not throws exception when `process isolation` is false
|
✓ 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
|
PASS Tests\Unit\Datasets
|
||||||
✓ it show the names of named datasets in their description
|
✓ it show the names of named datasets in their description
|
||||||
|
|
||||||
@ -374,6 +377,9 @@
|
|||||||
PASS Tests\Unit\TestSuite
|
PASS Tests\Unit\TestSuite
|
||||||
✓ it does not allow to add the same test description twice
|
✓ 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
|
PASS Tests\Visual\SingleTestOrDirectory
|
||||||
✓ allows to run a single test
|
✓ allows to run a single test
|
||||||
✓ allows to run a directory
|
✓ allows to run a directory
|
||||||
@ -391,5 +397,5 @@
|
|||||||
✓ depends with defined arguments
|
✓ depends with defined arguments
|
||||||
✓ depends run test only once
|
✓ depends run test only once
|
||||||
|
|
||||||
Tests: 7 skipped, 231 passed
|
Tests: 7 skipped, 233 passed
|
||||||
|
|
||||||
12
tests/Unit/Console/Help.php
Normal file
12
tests/Unit/Console/Help.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Console\Help;
|
||||||
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
|
||||||
|
it('outputs the help information when --help is used', function () {
|
||||||
|
$output = new BufferedOutput();
|
||||||
|
$plugin = new Help($output);
|
||||||
|
|
||||||
|
$plugin();
|
||||||
|
expect($output->fetch())->toContain('Pest Options:');
|
||||||
|
});
|
||||||
27
tests/Visual/Help.php
Normal file
27
tests/Visual/Help.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Console\Help;
|
||||||
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
|
||||||
|
test('visual snapshot of help command output', function () {
|
||||||
|
$snapshot = __DIR__ . '/../.snapshots/help-command.txt';
|
||||||
|
|
||||||
|
if (getenv('REBUILD_SNAPSHOTS')) {
|
||||||
|
$outputBuffer = new BufferedOutput();
|
||||||
|
$plugin = new Help($outputBuffer);
|
||||||
|
|
||||||
|
$plugin();
|
||||||
|
|
||||||
|
file_put_contents($snapshot, $outputBuffer->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');
|
||||||
Reference in New Issue
Block a user