diff --git a/composer.json b/composer.json index 4d50f7b0..b5da2599 100644 --- a/composer.json +++ b/composer.json @@ -79,6 +79,7 @@ }, "pest": { "plugins": [ + "Pest\\Plugins\\Memory", "Pest\\Plugins\\Coverage", "Pest\\Plugins\\Init", "Pest\\Plugins\\Version", diff --git a/src/Plugins/Memory.php b/src/Plugins/Memory.php new file mode 100644 index 00000000..ffaf3358 --- /dev/null +++ b/src/Plugins/Memory.php @@ -0,0 +1,50 @@ +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( + ' Memory: %s MB', + round(memory_get_usage(true) / pow(1000, 2), 3) + )); + } + + return $result; + } +}