Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 24 additions & 6 deletions src/Command/ParallelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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',
)
;
}

Expand Down Expand Up @@ -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
Expand All @@ -127,7 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('- Will be consumed by <fg=white;bg=blue>'.$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(
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
54 changes: 54 additions & 0 deletions src/UI/NoProgressRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Liuggio\Fastest\UI;

use Liuggio\Fastest\Process\Processes;
use Liuggio\Fastest\Queue\QueueInterface;
use Symfony\Component\Console\Output\OutputInterface;

class NoProgressRenderer implements RendererInterface
{
/**
* @var OutputInterface
*/
private $output;

/**
* @var bool
*/
private $errorsSummary;

/**
* @param bool $errorsSummary Whether to display errors summary in the footer
* @param OutputInterface $output
*/
public function __construct(bool $errorsSummary, OutputInterface $output)
{
$this->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 = ' <info>✔</info> You are great!';
if (!$processes->isSuccessful()) {
$out = ' <error>✘ ehm broken tests...</error>';
}

$this->output->writeln(PHP_EOL . $out);
}
}
Loading