mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
refacto: memory plugin
This commit is contained in:
@ -79,12 +79,12 @@
|
|||||||
},
|
},
|
||||||
"pest": {
|
"pest": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"Pest\\Plugins\\Memory",
|
|
||||||
"Pest\\Plugins\\Coverage",
|
"Pest\\Plugins\\Coverage",
|
||||||
"Pest\\Plugins\\Init",
|
"Pest\\Plugins\\Init",
|
||||||
"Pest\\Plugins\\Version",
|
|
||||||
"Pest\\Plugins\\Environment",
|
"Pest\\Plugins\\Environment",
|
||||||
"Pest\\Plugins\\Retry"
|
"Pest\\Plugins\\Memory",
|
||||||
|
"Pest\\Plugins\\Retry",
|
||||||
|
"Pest\\Plugins\\Version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"laravel": {
|
"laravel": {
|
||||||
|
|||||||
@ -46,9 +46,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, string> $originals
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return array<int, string>
|
|
||||||
*/
|
*/
|
||||||
public function handleArguments(array $originals): array
|
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()) {
|
if (!\Pest\Support\Coverage::isAvailable()) {
|
||||||
$this->output->writeln(
|
$this->output->writeln(
|
||||||
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
|
"\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);
|
$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(
|
$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 %%</>.",
|
"\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),
|
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;
|
private static ?string $name = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to handle custom command line arguments.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param array<int, string> $arguments
|
|
||||||
*
|
|
||||||
* @return array<int, string> the updated list of arguments
|
|
||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,6 +38,9 @@ final class Init implements HandlesArguments
|
|||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if (!array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) {
|
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
|
final class Memory implements AddsOutput, HandlesArguments
|
||||||
{
|
{
|
||||||
/** @var OutputInterface */
|
use Concerns\HandleArguments;
|
||||||
private $output;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If memory should be displayed.
|
||||||
|
*/
|
||||||
private bool $enabled = false;
|
private bool $enabled = false;
|
||||||
|
|
||||||
public function __construct(OutputInterface $output)
|
/**
|
||||||
{
|
* Creates a new Plugin instance.
|
||||||
$this->output = $output;
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private OutputInterface $output
|
||||||
|
) {
|
||||||
|
// ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
foreach ($arguments as $index => $argument) {
|
$this->enabled = $this->hasArgument('--memory', $arguments);
|
||||||
if ($argument === '--memory') {
|
|
||||||
unset($arguments[$index]);
|
|
||||||
|
|
||||||
$this->enabled = true;
|
return $this->popArgument('--memory', $arguments);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_values($arguments);
|
/**
|
||||||
}
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function addOutput(int $result): int
|
public function addOutput(int $exitCode): int
|
||||||
{
|
{
|
||||||
if ($this->enabled) {
|
if ($this->enabled) {
|
||||||
$this->output->writeln(sprintf(
|
$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;
|
use Concerns\HandleArguments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the plugin.
|
* Creates a new Plugin instance.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private OutputInterface $output
|
private OutputInterface $output
|
||||||
@ -24,6 +24,9 @@ final class Version implements HandlesArguments
|
|||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if ($this->hasArgument('--version', $arguments)) {
|
if ($this->hasArgument('--version', $arguments)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user