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