mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
refacto: memory plugin
This commit is contained in:
@ -79,12 +79,12 @@
|
||||
},
|
||||
"pest": {
|
||||
"plugins": [
|
||||
"Pest\\Plugins\\Memory",
|
||||
"Pest\\Plugins\\Coverage",
|
||||
"Pest\\Plugins\\Init",
|
||||
"Pest\\Plugins\\Version",
|
||||
"Pest\\Plugins\\Environment",
|
||||
"Pest\\Plugins\\Retry"
|
||||
"Pest\\Plugins\\Memory",
|
||||
"Pest\\Plugins\\Retry",
|
||||
"Pest\\Plugins\\Version"
|
||||
]
|
||||
},
|
||||
"laravel": {
|
||||
|
||||
@ -46,9 +46,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $originals
|
||||
*
|
||||
* @return array<int, string>
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleArguments(array $originals): array
|
||||
{
|
||||
@ -90,11 +88,11 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to add custom output after the test suite was executed.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addOutput(int $result): int
|
||||
public function addOutput(int $exitCode): int
|
||||
{
|
||||
if ($result === 0 && $this->coverage) {
|
||||
if ($exitCode === 0 && $this->coverage) {
|
||||
if (!\Pest\Support\Coverage::isAvailable()) {
|
||||
$this->output->writeln(
|
||||
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
||||
@ -104,9 +102,9 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
|
||||
$coverage = \Pest\Support\Coverage::report($this->output);
|
||||
|
||||
$result = (int) ($coverage < $this->coverageMin);
|
||||
$exitCode = (int) ($coverage < $this->coverageMin);
|
||||
|
||||
if ($result === 1) {
|
||||
if ($exitCode === 1) {
|
||||
$this->output->writeln(sprintf(
|
||||
"\n <fg=white;bg=red;options=bold> FAIL </> Code coverage below expected:<fg=red;options=bold> %s %%</>. Minimum:<fg=white;options=bold> %s %%</>.",
|
||||
number_format($coverage, 1),
|
||||
@ -115,6 +113,6 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,11 +27,7 @@ final class Environment implements HandlesArguments
|
||||
private static ?string $name = null;
|
||||
|
||||
/**
|
||||
* Allows to handle custom command line arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @return array<int, string> the updated list of arguments
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
|
||||
@ -38,6 +38,9 @@ final class Init implements HandlesArguments
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (!array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) {
|
||||
|
||||
@ -13,30 +13,36 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
final class Memory implements AddsOutput, HandlesArguments
|
||||
{
|
||||
/** @var OutputInterface */
|
||||
private $output;
|
||||
use Concerns\HandleArguments;
|
||||
|
||||
/**
|
||||
* If memory should be displayed.
|
||||
*/
|
||||
private bool $enabled = false;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
/**
|
||||
* Creates a new Plugin instance.
|
||||
*/
|
||||
public function __construct(
|
||||
private OutputInterface $output
|
||||
) {
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
foreach ($arguments as $index => $argument) {
|
||||
if ($argument === '--memory') {
|
||||
unset($arguments[$index]);
|
||||
$this->enabled = $this->hasArgument('--memory', $arguments);
|
||||
|
||||
$this->enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($arguments);
|
||||
return $this->popArgument('--memory', $arguments);
|
||||
}
|
||||
|
||||
public function addOutput(int $result): int
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addOutput(int $exitCode): int
|
||||
{
|
||||
if ($this->enabled) {
|
||||
$this->output->writeln(sprintf(
|
||||
@ -45,6 +51,6 @@ final class Memory implements AddsOutput, HandlesArguments
|
||||
));
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ final class Version implements HandlesArguments
|
||||
use Concerns\HandleArguments;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the plugin.
|
||||
* Creates a new Plugin instance.
|
||||
*/
|
||||
public function __construct(
|
||||
private OutputInterface $output
|
||||
@ -24,6 +24,9 @@ final class Version implements HandlesArguments
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if ($this->hasArgument('--version', $arguments)) {
|
||||
|
||||
Reference in New Issue
Block a user