From 7433cc5565a42928071686db9400c12d9492e59e Mon Sep 17 00:00:00 2001 From: Luke Downing Date: Wed, 22 Mar 2023 11:09:53 +0000 Subject: [PATCH] feat(parallel): Adds support for plugins to filter parallel arguments --- src/Plugins/Parallel.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Plugins/Parallel.php b/src/Plugins/Parallel.php index f4992d40..dbbaa9b9 100644 --- a/src/Plugins/Parallel.php +++ b/src/Plugins/Parallel.php @@ -14,6 +14,7 @@ use Pest\Support\Arr; use Pest\Support\Container; use Pest\TestSuite; use function Pest\version; +use Stringable; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArgvInput; @@ -21,6 +22,8 @@ final class Parallel implements HandlesArguments { use HandleArguments; + private const GLOBAL_PREFIX = 'PEST_PARALLEL_GLOBAL_'; + private const HANDLERS = [ Parallel\Handlers\Parallel::class, Parallel\Handlers\Pest::class, @@ -57,6 +60,26 @@ final class Parallel implements HandlesArguments return ((int) $argvValue) === 1; } + public static function setGlobal(string $key, string|int|bool|Stringable $value): void + { + $data = ['value' => $value instanceof Stringable ? $value->__toString() : $value]; + + $_SERVER[self::GLOBAL_PREFIX.$key] = json_encode($data); + } + + public static function getGlobal(string $key): string|int|bool|null + { + $placesToCheck = [$_SERVER, $_ENV]; + + foreach ($placesToCheck as $location) { + if (array_key_exists(self::GLOBAL_PREFIX.$key, $location)) { + return json_decode($location[self::GLOBAL_PREFIX.$key])['value'] ?? null; + } + } + + return null; + } + /** * {@inheritdoc} */