diff --git a/README.md b/README.md index 41e22e8..d9f3178 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,7 @@ Options: --preserve-order (-o) Queue is randomized by default, with this option the queue is read preserving the order. --rerun-failed (-r) Re-run failed test with before command if exists. --no-errors-summary Do not display all errors after the test run. Useful with --vv because it already displays errors immediately after they happen. + --no-progress Do not display progress bar when running. --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug diff --git a/src/Command/ParallelCommand.php b/src/Command/ParallelCommand.php index 6dfe45b..a242da7 100644 --- a/src/Command/ParallelCommand.php +++ b/src/Command/ParallelCommand.php @@ -18,6 +18,7 @@ use Liuggio\Fastest\Process\ProcessorCounter; use Liuggio\Fastest\Queue\Infrastructure\InMemoryQueueFactory; use Liuggio\Fastest\Queue\ReadFromInputAndPushIntoTheQueue; +use Liuggio\Fastest\UI\NoProgressRenderer; use Symfony\Component\Stopwatch\Stopwatch; class ParallelCommand extends Command @@ -29,6 +30,7 @@ class ParallelCommand extends Command private const PRESERVE_ORDER_OPTION = 'preserve-order'; private const RERUN_FAILED_OPTION = 'rerun-failed'; private const NO_ERRORS_SUMMARY_OPTION = 'no-errors-summary'; + private const NO_PROGRESS_OPTION = 'no-progress'; protected function configure(): void { @@ -76,6 +78,12 @@ protected function configure(): void InputOption::VALUE_NONE, 'Do not display all errors after the test run. Useful with --vv because it already displays errors immediately after they happen.' ) + ->addOption( + self::NO_PROGRESS_OPTION, + null, + InputOption::VALUE_NONE, + 'Do not display progress', + ) ; } @@ -119,6 +127,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new \Exception(sprintf('%s should have a scalar (string) or null value', self::BEFORE_OPTION)); } + $noProgressOption = $input->getOption(self::NO_PROGRESS_OPTION); + if (!is_bool($noProgressOption) && null !== $noProgressOption) { + throw new \Exception(sprintf('%s should not have any value', self::NO_PROGRESS_OPTION)); + } + $noProgressOption = (bool) $noProgressOption; + $processManager = new ProcessesManager($maxNumberOfParallelProc, $processFactory, $beforeOption); // header @@ -127,7 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('- Will be consumed by '.$maxNumberOfParallelProc.' parallel Processes.'); // loop - $processes = $this->doExecute($input, $output, $queue, $processManager); + $processes = $this->doExecute($input, $output, $queue, $processManager, $noProgressOption); $event = $stopWatch->stop('execute'); $output->writeln(sprintf( @@ -137,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int )); if ($input->getOption(self::RERUN_FAILED_OPTION)) { - $processes = $this->executeBeforeCommand($queue, $processes, $input, $output, $processManager); + $processes = $this->executeBeforeCommand($queue, $processes, $input, $output, $processManager, $noProgressOption); } return $processes->getExitCode(); @@ -158,11 +172,14 @@ private function doExecute( InputInterface $input, OutputInterface $output, QueueInterface $queue, - ProcessesManager $processManager + ProcessesManager $processManager, + bool $noProgressOption ): Processes { $processes = null; - if ($this->isVerbose($output)) { + if ($noProgressOption) { + $progressBar = new NoProgressRenderer($this->hasErrorSummary($input), $output); + } elseif ($this->isVerbose($output)) { $progressBar = new VerboseRenderer($queue->count(), $this->hasErrorSummary($input), $output); } else { $progressBar = new ProgressBarRenderer($queue->count(), $this->hasErrorSummary($input), $output); @@ -201,13 +218,14 @@ private function executeBeforeCommand( Processes $processes, InputInterface $input, OutputInterface $output, - ProcessesManager $processManager + ProcessesManager $processManager, + bool $noProgressOption ): Processes { if (!$processes->isSuccessful()) { $array = $processes->getErrorOutput(); $output->writeln(sprintf('Re-Running [%d] elements', count($array))); $queue->push(new TestsQueue(array_keys($array))); - $processes = $this->doExecute($input, $output, $queue, $processManager); + $processes = $this->doExecute($input, $output, $queue, $processManager, $noProgressOption); } return $processes; diff --git a/src/UI/NoProgressRenderer.php b/src/UI/NoProgressRenderer.php new file mode 100644 index 0000000..7cd2ff3 --- /dev/null +++ b/src/UI/NoProgressRenderer.php @@ -0,0 +1,54 @@ +errorsSummary = $errorsSummary; + $this->output = $output; + } + + public function renderHeader(QueueInterface $queue): void + { + } + + public function renderBody(QueueInterface $queue, Processes $processes): int + { + return $processes->countErrors(); + } + + public function renderFooter(QueueInterface $queue, Processes $processes): void + { + $this->output->writeln(''); + if ($this->errorsSummary) { + $this->output->writeln($processes->getErrorOutput()); + } + + $out = ' You are great!'; + if (!$processes->isSuccessful()) { + $out = ' ✘ ehm broken tests...'; + } + + $this->output->writeln(PHP_EOL . $out); + } +}