mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47: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
|
* If this code is running in a worker process rather than the main process.
|
||||||
*/
|
|
||||||
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
|
|
||||||
*/
|
*/
|
||||||
public static function isWorker(): bool
|
public static function isWorker(): bool
|
||||||
{
|
{
|
||||||
@ -57,23 +42,28 @@ final class Parallel implements HandlesArguments
|
|||||||
return ((int) $argvValue) === 1;
|
return ((int) $argvValue) === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if ($this->argumentsContainParallelFlags($arguments)) {
|
if ($this->argumentsContainParallelOptions($arguments)) {
|
||||||
exit($this->runTestSuiteInParallel($arguments));
|
exit($this->runTestSuiteInParallel($arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::isWorker()) {
|
if (self::isWorker()) {
|
||||||
return $this->runWorkersHandlers($arguments);
|
return $this->runWorkerHandlers($arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Whether the given command line arguments indicate that the test suite should be run in parallel.
|
||||||
|
*
|
||||||
* @param array<int, string> $arguments
|
* @param array<int, string> $arguments
|
||||||
*/
|
*/
|
||||||
private function argumentsContainParallelFlags(array $arguments): bool
|
private function argumentsContainParallelOptions(array $arguments): bool
|
||||||
{
|
{
|
||||||
if ($this->hasArgument('--parallel', $arguments)) {
|
if ($this->hasArgument('--parallel', $arguments)) {
|
||||||
return true;
|
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
|
* @param array<int, string> $arguments
|
||||||
*
|
*
|
||||||
* @throws JsonException
|
* @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
|
* @param array<int, string> $arguments
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
private function runWorkersHandlers(array $arguments): array
|
private function runWorkerHandlers(array $arguments): array
|
||||||
{
|
{
|
||||||
$handlers = array_filter(
|
$handlers = array_filter(
|
||||||
array_map(fn ($handler): object|string => Container::getInstance()->get($handler), self::HANDLERS),
|
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
|
private function askUserToInstallParatest(): void
|
||||||
{
|
{
|
||||||
/** @var OutputInterface $output */
|
/** @var OutputInterface $output */
|
||||||
@ -142,6 +139,9 @@ final class Parallel implements HandlesArguments
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds an instance of the Paratest command.
|
||||||
|
*/
|
||||||
private function paratestCommand(): Application
|
private function paratestCommand(): Application
|
||||||
{
|
{
|
||||||
/** @var non-empty-string $rootPath */
|
/** @var non-empty-string $rootPath */
|
||||||
|
|||||||
@ -21,6 +21,9 @@ final class Laravel implements HandlesArguments
|
|||||||
{
|
{
|
||||||
use HandleArguments;
|
use HandleArguments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
return self::whenUsingLaravel($arguments, function (array $arguments): array {
|
return self::whenUsingLaravel($arguments, function (array $arguments): array {
|
||||||
@ -43,10 +46,8 @@ final class Laravel implements HandlesArguments
|
|||||||
{
|
{
|
||||||
$isLaravelApplication = InstalledVersions::isInstalled('laravel/framework', false);
|
$isLaravelApplication = InstalledVersions::isInstalled('laravel/framework', false);
|
||||||
$isLaravelPackage = class_exists(\Orchestra\Testbench\TestCase::class);
|
$isLaravelPackage = class_exists(\Orchestra\Testbench\TestCase::class);
|
||||||
if ($isLaravelApplication) {
|
|
||||||
return $closure($arguments);
|
if ($isLaravelApplication && ! $isLaravelPackage) {
|
||||||
}
|
|
||||||
if ($isLaravelPackage) {
|
|
||||||
return $closure($arguments);
|
return $closure($arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ final class Parallel implements HandlesArguments
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the arguments, removing the ones that are not needed, and adding the "runner" argument.
|
* Handles the arguments, removing the ones that are not needed, and adds the "runner" argument.
|
||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -33,7 +33,7 @@ final class AfterEachRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a after each closure by the given filename.
|
* Gets an after each closure by the given filename.
|
||||||
*/
|
*/
|
||||||
public function get(string $filename): Closure
|
public function get(string $filename): Closure
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user