Merge pull request #118 from owenvoke/feature/thanks

Add --thanks option plugin
This commit is contained in:
Nuno Maduro
2020-07-01 18:51:54 +02:00
committed by GitHub
4 changed files with 67 additions and 2 deletions

View File

@ -85,6 +85,7 @@
}, },
"pest": { "pest": {
"plugins": [ "plugins": [
"Pest\\Plugins\\Thanks",
"Pest\\Plugins\\Version" "Pest\\Plugins\\Version"
] ]
}, },

46
src/Plugins/Thanks.php Normal file
View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Pest\Plugins;
use Pest\Contracts\Plugins\HandlesArguments;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @internal
*/
final class Thanks implements HandlesArguments
{
private const THANKS_OPTION = '--thanks';
/** @var array<int, string> */
private const FUNDING_MESSAGES = [
"\n Want to support Pest? Here are some ways you can help:",
"\n - Star or contribute to Pest on GitHub:\n <options=bold>https://github.com/pestphp/pest</>",
"\n - Tweet about Pest on Twitter:\n <options=bold>https://twitter.com/pestphp</>",
"\n - Sponsor Nuno Maduro on GitHub:\n <options=bold>https://github.com/sponsors/nunomaduro</>",
"\n - Sponsor Nuno Maduro on Patreon:\n <options=bold>https://patreon.com/nunomaduro</>",
];
/** @var OutputInterface */
private $output;
public function __construct(OutputInterface $output)
{
$this->output = $output;
}
public function handleArguments(array $arguments): array
{
if (!in_array(self::THANKS_OPTION, $arguments, true)) {
return $arguments;
}
foreach (self::FUNDING_MESSAGES as $message) {
$this->output->writeln($message);
}
exit(0);
}
}

View File

@ -135,6 +135,10 @@
✓ 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
WARN Tests\Unit\Plugins\Thanks
- it outputs funding options when --thanks is used → The plugin uses `exit()` so not sure how to implement this
✓ it does not output funding options when --thanks is not used
PASS Tests\Unit\Plugins\Version PASS Tests\Unit\Plugins\Version
✓ it outputs the version when --version is used ✓ it outputs the version when --version is used
✓ it do not outputs version when --version is not used ✓ it do not outputs version when --version is not used
@ -167,5 +171,5 @@
WARN Tests\Visual\Success WARN Tests\Visual\Success
- visual snapshot of test suite on success - visual snapshot of test suite on success
Tests: 6 skipped, 96 passed Tests: 7 skipped, 97 passed
Time: 3.56s Time: 3.57s

View File

@ -0,0 +1,14 @@
<?php
use Pest\Plugins\Thanks;
use Symfony\Component\Console\Output\BufferedOutput;
it('outputs funding options when --thanks is used')->skip('The plugin uses `exit()` so not sure how to implement this');
it('does not output funding options when --thanks is not used', function () {
$output = new BufferedOutput();
$plugin = new Thanks($output);
$plugin->handleArguments(['foo', 'bar']);
assertEquals('', $output->fetch());
});