mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
chore(cleanup): Tidy-up and tweaks of Pest Parallel integration.
This commit is contained in:
@ -31,22 +31,7 @@ final class Parallel implements HandlesArguments
|
||||
];
|
||||
|
||||
/**
|
||||
* If the
|
||||
*/
|
||||
public static function isCommand(): bool
|
||||
{
|
||||
// get binary name
|
||||
Arr::get($_SERVER, 'argv.0');
|
||||
|
||||
$argvValue = Arr::get($_ENV, 'PARATEST');
|
||||
|
||||
assert(is_string($argvValue) || is_int($argvValue) || is_null($argvValue));
|
||||
|
||||
return ((int) $argvValue) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the
|
||||
* If this code is running in a worker process rather than the main process.
|
||||
*/
|
||||
public static function isWorker(): bool
|
||||
{
|
||||
@ -57,23 +42,28 @@ final class Parallel implements HandlesArguments
|
||||
return ((int) $argvValue) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if ($this->argumentsContainParallelFlags($arguments)) {
|
||||
if ($this->argumentsContainParallelOptions($arguments)) {
|
||||
exit($this->runTestSuiteInParallel($arguments));
|
||||
}
|
||||
|
||||
if (self::isWorker()) {
|
||||
return $this->runWorkersHandlers($arguments);
|
||||
return $this->runWorkerHandlers($arguments);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the given command line arguments indicate that the test suite should be run in parallel.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*/
|
||||
private function argumentsContainParallelFlags(array $arguments): bool
|
||||
private function argumentsContainParallelOptions(array $arguments): bool
|
||||
{
|
||||
if ($this->hasArgument('--parallel', $arguments)) {
|
||||
return true;
|
||||
@ -83,6 +73,8 @@ final class Parallel implements HandlesArguments
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the test suite in parallel. This method will exit the process upon completion.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
*
|
||||
* @throws JsonException
|
||||
@ -114,10 +106,12 @@ final class Parallel implements HandlesArguments
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs any handlers that have been registered to handle worker arguments, and returns the modified arguments.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function runWorkersHandlers(array $arguments): array
|
||||
private function runWorkerHandlers(array $arguments): array
|
||||
{
|
||||
$handlers = array_filter(
|
||||
array_map(fn ($handler): object|string => Container::getInstance()->get($handler), self::HANDLERS),
|
||||
@ -131,6 +125,9 @@ final class Parallel implements HandlesArguments
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a message to the user asking them to install ParaTest as a dev dependency.
|
||||
*/
|
||||
private function askUserToInstallParatest(): void
|
||||
{
|
||||
/** @var OutputInterface $output */
|
||||
@ -142,6 +139,9 @@ final class Parallel implements HandlesArguments
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an instance of the Paratest command.
|
||||
*/
|
||||
private function paratestCommand(): Application
|
||||
{
|
||||
/** @var non-empty-string $rootPath */
|
||||
|
||||
Reference in New Issue
Block a user