mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
refactor: parallel
This commit is contained in:
@ -14,6 +14,9 @@ final class Cache implements HandlesArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
/**
|
||||
* The temporary folder.
|
||||
*/
|
||||
private const TEMPORARY_FOLDER = __DIR__
|
||||
.DIRECTORY_SEPARATOR
|
||||
.'..'
|
||||
@ -23,7 +26,7 @@ final class Cache implements HandlesArguments
|
||||
.'.temp';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Handles the arguments, adding the cache directory and the cache result arguments.
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@ final class Parallel implements HandlesArguments
|
||||
use HandleArguments;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* The list of arguments to remove.
|
||||
*/
|
||||
private const ARGS_TO_REMOVE = [
|
||||
'--parallel',
|
||||
@ -24,6 +24,9 @@ final class Parallel implements HandlesArguments
|
||||
'--no-output',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handles the arguments, removing the ones that are not needed, and adding the "runner" argument.
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
$args = array_reduce(self::ARGS_TO_REMOVE, fn ($args, $arg): array => $this->popArgument($arg, $args), $arguments);
|
||||
|
||||
@ -11,6 +11,9 @@ final class Pest implements HandlersWorkerArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
/**
|
||||
* Handles the arguments, adding the "PEST_PARALLEL" environment variable to the global $_SERVER.
|
||||
*/
|
||||
public function handleWorkerArguments(array $arguments): array
|
||||
{
|
||||
$_SERVER['PEST_PARALLEL'] = '1';
|
||||
|
||||
@ -21,8 +21,7 @@ final class CleanConsoleOutput extends ConsoleOutput
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given message is the descriptive message
|
||||
* that Paratest outputs when it starts.
|
||||
* Removes the opening headline, witch is not needed.
|
||||
*/
|
||||
private function isOpeningHeadline(string $message): bool
|
||||
{
|
||||
|
||||
@ -28,12 +28,16 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
/** @internal */
|
||||
final class ResultPrinter
|
||||
{
|
||||
/**
|
||||
* The "native" printer.
|
||||
*/
|
||||
public readonly Printer $printer;
|
||||
|
||||
/**
|
||||
* The "compact" printer.
|
||||
*/
|
||||
private readonly CompactPrinter $compactPrinter;
|
||||
|
||||
private int $totalCases = 0;
|
||||
|
||||
/** @var resource|null */
|
||||
private $teamcityLogFileHandle;
|
||||
|
||||
@ -61,7 +65,7 @@ final class ResultPrinter
|
||||
}
|
||||
};
|
||||
|
||||
$this->compactPrinter = new CompactPrinter();
|
||||
$this->compactPrinter = CompactPrinter::default();
|
||||
|
||||
if (! $this->options->configuration->hasLogfileTeamcity()) {
|
||||
return;
|
||||
@ -72,17 +76,12 @@ final class ResultPrinter
|
||||
$this->teamcityLogFileHandle = $teamcityLogFileHandle;
|
||||
}
|
||||
|
||||
public function setTestCount(int $testCount): void
|
||||
{
|
||||
$this->totalCases = $testCount;
|
||||
}
|
||||
|
||||
public function start(): void
|
||||
public function start(int $numberOfTests): void
|
||||
{
|
||||
$this->compactPrinter->line(sprintf(
|
||||
'Running %d test%s using %d process%s',
|
||||
$this->totalCases,
|
||||
$this->totalCases === 1 ? '' : 's',
|
||||
$numberOfTests,
|
||||
$numberOfTests === 1 ? '' : 's',
|
||||
$this->options->processes,
|
||||
$this->options->processes === 1 ? '' : 'es')
|
||||
);
|
||||
|
||||
@ -121,8 +121,7 @@ final class WrapperRunner implements RunnerInterface
|
||||
|
||||
$result = TestResultFacade::result();
|
||||
|
||||
$this->printer->setTestCount($suiteLoader->testCount);
|
||||
$this->printer->start();
|
||||
$this->printer->start($suiteLoader->testCount);
|
||||
|
||||
$this->timer->start();
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ use PHPUnit\Event\Telemetry\Snapshot;
|
||||
use PHPUnit\TestRunner\TestResult\TestResult as PHPUnitTestResult;
|
||||
use SebastianBergmann\Timer\Duration;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use function Termwind\render;
|
||||
use Termwind\Terminal;
|
||||
use function Termwind\terminal;
|
||||
@ -23,15 +23,10 @@ use function Termwind\terminal;
|
||||
*/
|
||||
final class CompactPrinter
|
||||
{
|
||||
private readonly Terminal $terminal;
|
||||
|
||||
private readonly ConsoleOutputInterface $output;
|
||||
|
||||
private readonly Style $style;
|
||||
|
||||
private int $compactProcessed = 0;
|
||||
|
||||
private readonly int $compactSymbolsPerLine;
|
||||
/**
|
||||
* The number of processed tests.
|
||||
*/
|
||||
private int $processed = 0;
|
||||
|
||||
/**
|
||||
* @var array<string, array<int, string>>
|
||||
@ -47,13 +42,29 @@ final class CompactPrinter
|
||||
'F' => ['red', '⨯'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->terminal = terminal();
|
||||
$this->output = new ConsoleOutput(decorated: true);
|
||||
$this->style = new Style($this->output);
|
||||
/**
|
||||
* Creates a new instance of the Compact Printer.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Terminal $terminal,
|
||||
private readonly OutputInterface $output,
|
||||
private readonly Style $style,
|
||||
private readonly int $compactSymbolsPerLine,
|
||||
) {
|
||||
// ..
|
||||
}
|
||||
|
||||
$this->compactSymbolsPerLine = $this->terminal->width() - 4;
|
||||
/**
|
||||
* Creates a new instance of the Compact Printer.
|
||||
*/
|
||||
public static function default(): self
|
||||
{
|
||||
return new self(
|
||||
terminal(),
|
||||
new ConsoleOutput(decorated: true),
|
||||
new Style(new ConsoleOutput(decorated: true)),
|
||||
terminal()->width() - 4,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +90,7 @@ final class CompactPrinter
|
||||
{
|
||||
[$color, $icon] = self::LOOKUP_TABLE[$item] ?? self::LOOKUP_TABLE['.'];
|
||||
|
||||
$symbolsOnCurrentLine = $this->compactProcessed % $this->compactSymbolsPerLine;
|
||||
$symbolsOnCurrentLine = $this->processed % $this->compactSymbolsPerLine;
|
||||
|
||||
if ($symbolsOnCurrentLine >= $this->terminal->width() - 4) {
|
||||
$symbolsOnCurrentLine = 0;
|
||||
@ -92,7 +103,7 @@ final class CompactPrinter
|
||||
|
||||
$this->output->write(sprintf('<fg=%s;options=bold>%s</>', $color, $icon));
|
||||
|
||||
$this->compactProcessed++;
|
||||
$this->processed++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user