diff --git a/src/Framework/Attributes/RunClassInSeparateProcess.php b/src/Framework/Attributes/RunClassInSeparateProcess.php index 1ccd3bc6fb..e8918e5494 100644 --- a/src/Framework/Attributes/RunClassInSeparateProcess.php +++ b/src/Framework/Attributes/RunClassInSeparateProcess.php @@ -19,4 +19,15 @@ #[Attribute(Attribute::TARGET_CLASS)] final readonly class RunClassInSeparateProcess { + private ?bool $forkIfPossible; + + public function __construct(bool $forkIfPossible = null) + { + $this->forkIfPossible = $forkIfPossible; + } + + public function forkIfPossible(): ?bool + { + return $this->forkIfPossible; + } } diff --git a/src/Framework/Attributes/RunInSeparateProcess.php b/src/Framework/Attributes/RunInSeparateProcess.php index 838e267e2e..d10cbba3ef 100644 --- a/src/Framework/Attributes/RunInSeparateProcess.php +++ b/src/Framework/Attributes/RunInSeparateProcess.php @@ -19,4 +19,15 @@ #[Attribute(Attribute::TARGET_METHOD)] final readonly class RunInSeparateProcess { + private ?bool $forkIfPossible; + + public function __construct(?bool $forkIfPossible = null) + { + $this->forkIfPossible = $forkIfPossible; + } + + public function forkIfPossible(): ?bool + { + return $this->forkIfPossible; + } } diff --git a/src/Framework/Attributes/RunTestsInSeparateProcesses.php b/src/Framework/Attributes/RunTestsInSeparateProcesses.php index 19fea88239..ed804fa2a7 100644 --- a/src/Framework/Attributes/RunTestsInSeparateProcesses.php +++ b/src/Framework/Attributes/RunTestsInSeparateProcesses.php @@ -19,4 +19,15 @@ #[Attribute(Attribute::TARGET_CLASS)] final readonly class RunTestsInSeparateProcesses { + private ?bool $forkIfPossible; + + public function __construct(?bool $forkIfPossible = null) + { + $this->forkIfPossible = $forkIfPossible; + } + + public function forkIfPossible(): ?bool + { + return $this->forkIfPossible; + } } diff --git a/src/Metadata/Metadata.php b/src/Metadata/Metadata.php index d9a787b731..ce1296974c 100644 --- a/src/Metadata/Metadata.php +++ b/src/Metadata/Metadata.php @@ -390,19 +390,19 @@ public static function requiresSettingOnMethod(string $setting, string $value): return new RequiresSetting(self::METHOD_LEVEL, $setting, $value); } - public static function runClassInSeparateProcess(): RunClassInSeparateProcess + public static function runClassInSeparateProcess(?bool $forkIfPossible = null): RunClassInSeparateProcess { - return new RunClassInSeparateProcess(self::CLASS_LEVEL); + return new RunClassInSeparateProcess(self::CLASS_LEVEL, $forkIfPossible); } - public static function runTestsInSeparateProcesses(): RunTestsInSeparateProcesses + public static function runTestsInSeparateProcesses(?bool $forkIfPossible = null): RunTestsInSeparateProcesses { - return new RunTestsInSeparateProcesses(self::CLASS_LEVEL); + return new RunTestsInSeparateProcesses(self::CLASS_LEVEL, $forkIfPossible); } - public static function runInSeparateProcess(): RunInSeparateProcess + public static function runInSeparateProcess(?bool $forkIfPossible = null): RunInSeparateProcess { - return new RunInSeparateProcess(self::METHOD_LEVEL); + return new RunInSeparateProcess(self::METHOD_LEVEL, $forkIfPossible); } public static function test(): Test diff --git a/src/Metadata/Parser/AttributeParser.php b/src/Metadata/Parser/AttributeParser.php index 257c38e328..8b19fa387c 100644 --- a/src/Metadata/Parser/AttributeParser.php +++ b/src/Metadata/Parser/AttributeParser.php @@ -297,12 +297,20 @@ public function forClass(string $className): MetadataCollection break; case RunClassInSeparateProcess::class: - $result[] = Metadata::runClassInSeparateProcess(); + assert($attributeInstance instanceof RunClassInSeparateProcess); + + $result[] = Metadata::runClassInSeparateProcess( + $attributeInstance->forkIfPossible(), + ); break; case RunTestsInSeparateProcesses::class: - $result[] = Metadata::runTestsInSeparateProcesses(); + assert($attributeInstance instanceof RunTestsInSeparateProcesses); + + $result[] = Metadata::runTestsInSeparateProcesses( + $attributeInstance->forkIfPossible(), + ); break; @@ -638,7 +646,11 @@ public function forMethod(string $className, string $methodName): MetadataCollec break; case RunInSeparateProcess::class: - $result[] = Metadata::runInSeparateProcess(); + assert($attributeInstance instanceof RunInSeparateProcess); + + $result[] = Metadata::runInSeparateProcess( + $attributeInstance->forkIfPossible(), + ); break; diff --git a/src/Metadata/RunClassInSeparateProcess.php b/src/Metadata/RunClassInSeparateProcess.php index 907a45d452..a5b6aa7f82 100644 --- a/src/Metadata/RunClassInSeparateProcess.php +++ b/src/Metadata/RunClassInSeparateProcess.php @@ -16,6 +16,23 @@ */ final readonly class RunClassInSeparateProcess extends Metadata { + private ?bool $forkIfPossible; + + /** + * @psalm-param 0|1 $level + */ + protected function __construct(int $level, ?bool $forkIfPossible = null) + { + $this->forkIfPossible = $forkIfPossible; + + parent::__construct($level); + } + + public function forkIfPossible(): ?bool + { + return $this->forkIfPossible; + } + /** * @psalm-assert-if-true RunClassInSeparateProcess $this */ diff --git a/src/Metadata/RunInSeparateProcess.php b/src/Metadata/RunInSeparateProcess.php index 07febae09d..9b5cc237b0 100644 --- a/src/Metadata/RunInSeparateProcess.php +++ b/src/Metadata/RunInSeparateProcess.php @@ -16,6 +16,23 @@ */ final readonly class RunInSeparateProcess extends Metadata { + private ?bool $forkIfPossible; + + /** + * @psalm-param 0|1 $level + */ + protected function __construct(int $level, ?bool $forkIfPossible = null) + { + $this->forkIfPossible = $forkIfPossible; + + parent::__construct($level); + } + + public function forkIfPossible(): ?bool + { + return $this->forkIfPossible; + } + /** * @psalm-assert-if-true RunInSeparateProcess $this */ diff --git a/src/Metadata/RunTestsInSeparateProcesses.php b/src/Metadata/RunTestsInSeparateProcesses.php index b71233d3db..5a8275d293 100644 --- a/src/Metadata/RunTestsInSeparateProcesses.php +++ b/src/Metadata/RunTestsInSeparateProcesses.php @@ -16,6 +16,23 @@ */ final readonly class RunTestsInSeparateProcesses extends Metadata { + private ?bool $forkIfPossible; + + /** + * @psalm-param 0|1 $level + */ + protected function __construct(int $level, ?bool $forkIfPossible = null) + { + $this->forkIfPossible = $forkIfPossible; + + parent::__construct($level); + } + + public function forkIfPossible(): ?bool + { + return $this->forkIfPossible; + } + /** * @psalm-assert-if-true RunTestsInSeparateProcesses $this */