mirror of
https://github.com/pestphp/pest.git
synced 2026-03-13 03:07:22 +01:00
Merge pull request #433 from owenvoke/feature/memory-usage
feat: add `--memory` usage flag
This commit is contained in:
@ -79,6 +79,7 @@
|
|||||||
},
|
},
|
||||||
"pest": {
|
"pest": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"Pest\\Plugins\\Memory",
|
||||||
"Pest\\Plugins\\Coverage",
|
"Pest\\Plugins\\Coverage",
|
||||||
"Pest\\Plugins\\Init",
|
"Pest\\Plugins\\Init",
|
||||||
"Pest\\Plugins\\Version",
|
"Pest\\Plugins\\Version",
|
||||||
|
|||||||
50
src/Plugins/Memory.php
Normal file
50
src/Plugins/Memory.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
|
use Pest\Contracts\Plugins\AddsOutput;
|
||||||
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Memory implements AddsOutput, HandlesArguments
|
||||||
|
{
|
||||||
|
/** @var OutputInterface */
|
||||||
|
private $output;
|
||||||
|
|
||||||
|
private bool $enabled = false;
|
||||||
|
|
||||||
|
public function __construct(OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->output = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handleArguments(array $arguments): array
|
||||||
|
{
|
||||||
|
foreach ($arguments as $index => $argument) {
|
||||||
|
if ($argument === '--memory') {
|
||||||
|
unset($arguments[$index]);
|
||||||
|
|
||||||
|
$this->enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values($arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addOutput(int $result): int
|
||||||
|
{
|
||||||
|
if ($this->enabled) {
|
||||||
|
$this->output->writeln(sprintf(
|
||||||
|
' <fg=white;options=bold>Memory: </><fg=default>%s MB</>',
|
||||||
|
round(memory_get_usage(true) / pow(1000, 2), 3)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user