forked from sebastianbergmann/phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6319b7
commit b94977a
Showing
8 changed files
with
175 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,21 +29,25 @@ | |
use PHPUnit\Event; | ||
use PHPUnit\Event\Code\TestMethod; | ||
use PHPUnit\Event\NoPreviousThrowableException; | ||
use PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException; | ||
use PHPUnit\Metadata\Api\Dependencies; | ||
use PHPUnit\Metadata\Api\Groups; | ||
use PHPUnit\Metadata\Api\HookMethods; | ||
use PHPUnit\Metadata\Api\Requirements; | ||
use PHPUnit\Metadata\MetadataCollection; | ||
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry; | ||
use PHPUnit\Runner\Exception as RunnerException; | ||
use PHPUnit\Runner\Filter\Factory; | ||
use PHPUnit\Runner\PhptTestCase; | ||
use PHPUnit\Runner\TestSuiteLoader; | ||
use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade; | ||
use PHPUnit\Util\Exception as UtilException; | ||
use PHPUnit\Util\Filter; | ||
use PHPUnit\Util\Reflection; | ||
use PHPUnit\Util\Test as TestUtil; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
use SebastianBergmann\CodeCoverage\StaticAnalysisCacheNotConfiguredException; | ||
use SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException; | ||
use Throwable; | ||
|
||
|
@@ -68,9 +72,10 @@ class TestSuite implements IteratorAggregate, Reorderable, SelfDescribing, Test | |
/** | ||
* @psalm-var list<Test> | ||
*/ | ||
private array $tests = []; | ||
private ?array $providedTests = null; | ||
private ?Factory $iteratorFilter = null; | ||
private array $tests = []; | ||
private ?array $providedTests = null; | ||
private ?Factory $iteratorFilter = null; | ||
private ?bool $runClassInSeparateProcess = null; | ||
|
||
/** | ||
* @psalm-param non-empty-string $name | ||
|
@@ -134,6 +139,10 @@ public static function fromClassReflector(ReflectionClass $class): static | |
); | ||
} | ||
|
||
if ($testSuite->shouldAllTestMethodsOfTestClassBeRunInSingleSeparateProcess($class->getName())) { | ||
$testSuite->setRunClassInSeparateProcess(true); | ||
} | ||
|
||
return $testSuite; | ||
} | ||
|
||
|
@@ -312,8 +321,13 @@ public function groupDetails(): array | |
* @throws CodeCoverageException | ||
* @throws Event\RuntimeException | ||
* @throws Exception | ||
* @throws MoreThanOneDataSetFromDataProviderException | ||
* @throws NoPreviousThrowableException | ||
* @throws ProcessIsolationException | ||
* @throws RunnerException | ||
* @throws StaticAnalysisCacheNotConfiguredException | ||
* @throws UnintentionallyCoveredCodeException | ||
* @throws UtilException | ||
*/ | ||
public function run(): void | ||
{ | ||
|
@@ -330,14 +344,22 @@ public function run(): void | |
return; | ||
} | ||
|
||
foreach ($this as $test) { | ||
if (TestResultFacade::shouldStop()) { | ||
$emitter->testRunnerExecutionAborted(); | ||
if ($this->shouldRunInSeparateProcess()) { | ||
(new TestRunner)->runInSeparateProcess($this, false); | ||
Check failure on line 348 in src/Framework/TestSuite.php GitHub Actions / Type CheckerMissingThrowsDocblock
|
||
} else { | ||
foreach ($this as $test) { | ||
if (TestResultFacade::shouldStop()) { | ||
$emitter->testRunnerExecutionAborted(); | ||
|
||
break; | ||
} | ||
break; | ||
} | ||
|
||
$test->run(); | ||
if ($test instanceof self && $test->shouldRunInSeparateProcess()) { | ||
(new TestRunner)->runInSeparateProcess($test, false); | ||
} else { | ||
$test->run(); | ||
} | ||
} | ||
} | ||
|
||
$this->invokeMethodsAfterLastTest($emitter); | ||
|
@@ -462,9 +484,18 @@ public function isForTestClass(): bool | |
return class_exists($this->name, false) && is_subclass_of($this->name, TestCase::class); | ||
} | ||
|
||
public function shouldRunInSeparateProcess(): bool | ||
{ | ||
if ($this->runClassInSeparateProcess) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @throws \PHPUnit\Event\TestData\MoreThanOneDataSetFromDataProviderException | ||
* @throws Exception | ||
* @throws MoreThanOneDataSetFromDataProviderException | ||
*/ | ||
protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void | ||
{ | ||
|
@@ -679,4 +710,19 @@ private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void | |
); | ||
} | ||
} | ||
|
||
private function setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void | ||
{ | ||
if ($this->runClassInSeparateProcess === null) { | ||
$this->runClassInSeparateProcess = $runClassInSeparateProcess; | ||
} | ||
} | ||
|
||
/** | ||
* @psalm-param class-string $className | ||
*/ | ||
private function shouldAllTestMethodsOfTestClassBeRunInSingleSeparateProcess(string $className): bool | ||
{ | ||
return MetadataRegistry::parser()->forClass($className)->isRunClassInSeparateProcess()->isNotEmpty(); | ||
} | ||
} |
Oops, something went wrong.