mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
refactor: thanks
This commit is contained in:
@ -85,7 +85,6 @@
|
||||
},
|
||||
"pest": {
|
||||
"plugins": [
|
||||
"Pest\\Plugins\\Thanks",
|
||||
"Pest\\Plugins\\Version"
|
||||
]
|
||||
},
|
||||
|
||||
66
src/Console/Thanks.php
Normal file
66
src/Console/Thanks.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Console;
|
||||
|
||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Thanks
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
private const FUNDING_MESSAGES = [
|
||||
'',
|
||||
' - Star or contribute to Pest:',
|
||||
' <options=bold>https://github.com/pestphp/pest</>',
|
||||
' - Tweet something about Pest on Twitter:',
|
||||
' <options=bold>https://twitter.com/pestphp</>',
|
||||
' - Sponsor the creator:',
|
||||
' <options=bold>https://github.com/sponsors/nunomaduro</>',
|
||||
];
|
||||
|
||||
/** @var OutputInterface */
|
||||
private $output;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the user to support Pest.
|
||||
*/
|
||||
public function __invoke(): void
|
||||
{
|
||||
$wantsToSupport = (new SymfonyQuestionHelper())->ask(
|
||||
new ArrayInput([]),
|
||||
$this->output,
|
||||
new ConfirmationQuestion(
|
||||
'Can you quickly <options=bold>star our GitHub repository</>? 🙏🏻',
|
||||
true,
|
||||
)
|
||||
);
|
||||
|
||||
if ($wantsToSupport === true) {
|
||||
if (PHP_OS_FAMILY == 'Darwin') {
|
||||
exec('open https://github.com/pestphp/pest');
|
||||
}
|
||||
if (PHP_OS_FAMILY == 'Windows') {
|
||||
exec('start https://github.com/pestphp/pest');
|
||||
}
|
||||
if (PHP_OS_FAMILY == 'Linux') {
|
||||
exec('xdg-open https://github.com/pestphp/pest');
|
||||
}
|
||||
}
|
||||
|
||||
foreach (self::FUNDING_MESSAGES as $message) {
|
||||
$this->output->writeln($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,6 +59,8 @@ final class PestInstallCommand extends Command
|
||||
|
||||
$this->output->success('`tests/Pest.php` created successfully.');
|
||||
$this->output->success('`tests/Helpers.php` created successfully.');
|
||||
|
||||
(new \Pest\Console\Thanks($this->output))();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@ -135,10 +135,6 @@
|
||||
✓ it throws exception when `process isolation` is true
|
||||
✓ 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
|
||||
✓ it outputs the version when --version is used
|
||||
✓ it do not outputs version when --version is not used
|
||||
@ -171,5 +167,5 @@
|
||||
WARN Tests\Visual\Success
|
||||
- visual snapshot of test suite on success
|
||||
|
||||
Tests: 7 skipped, 97 passed
|
||||
Time: 3.57s
|
||||
Tests: 6 skipped, 96 passed
|
||||
Time: 3.43s
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
<?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());
|
||||
});
|
||||
Reference in New Issue
Block a user