Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Pest options to help output #217

Merged
merged 6 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,7 @@ protected function showHelp(): void
$version = Container::getInstance()->get(Version::class);
$version->handleArguments(['--version']);
parent::showHelp();

(new Help($this->output))();
}
}
37 changes: 37 additions & 0 deletions src/Console/Help.php
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/.snapshots/help-command.txt
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 7 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
owenvoke marked this conversation as resolved.
Show resolved Hide resolved

PASS Tests\Unit\Datasets
✓ it show the names of named datasets in their description

Expand All @@ -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
Expand All @@ -391,5 +397,5 @@
✓ depends with defined arguments
✓ depends run test only once

Tests: 7 skipped, 231 passed
Tests: 7 skipped, 233 passed

12 changes: 12 additions & 0 deletions tests/Unit/Console/Help.php
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions tests/Visual/Help.php
Original file line number Diff line number Diff line change
@@ -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');