Merge pull request #217 from owenvoke/feature/help

feat: add Pest options to help output
This commit is contained in:
Owen Voke
2020-11-12 14:59:50 +00:00
committed by GitHub
6 changed files with 90 additions and 1 deletions

View File

@ -148,5 +148,7 @@ final class Command extends BaseCommand
$version = Container::getInstance()->get(Version::class);
$version->handleArguments(['--version']);
parent::showHelp();
(new Help($this->output))();
}
}

37
src/Console/Help.php Normal file
View 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);
}
}
}

View 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)

View File

@ -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

View 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
View 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');