mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 01:37:21 +01:00
feat: adds --retry option
This commit is contained in:
37
src/Plugins/Concerns/HandleArguments.php
Normal file
37
src/Plugins/Concerns/HandleArguments.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Concerns;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
trait HandleArguments
|
||||
{
|
||||
/**
|
||||
* Checks if the given argument exists on the arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*/
|
||||
public function hasArgument(string $argument, array $arguments): bool
|
||||
{
|
||||
return in_array($argument, $arguments, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops the given argument from the arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function popArgument(string $argument, array $arguments): array
|
||||
{
|
||||
$arguments = array_flip($arguments);
|
||||
|
||||
unset($arguments[$argument]);
|
||||
|
||||
return array_flip($arguments);
|
||||
}
|
||||
}
|
||||
30
src/Plugins/Retry.php
Normal file
30
src/Plugins/Retry.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Retry implements HandlesArguments
|
||||
{
|
||||
use Concerns\HandleArguments;
|
||||
|
||||
/**
|
||||
* Whether it should show retry or not.
|
||||
*/
|
||||
public static bool $retrying = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
self::$retrying = $this->hasArgument('--retry', $arguments);
|
||||
|
||||
return $this->popArgument('--retry', $arguments);
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
final class Version implements HandlesArguments
|
||||
{
|
||||
use Concerns\HandleArguments;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the plugin.
|
||||
*/
|
||||
@ -24,7 +26,7 @@ final class Version implements HandlesArguments
|
||||
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (in_array('--version', $arguments, true)) {
|
||||
if ($this->hasArgument('--version', $arguments)) {
|
||||
$this->output->writeln(
|
||||
sprintf('Pest %s', version()),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user