mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Bugfix. The TestCase is now aware of if it is running in parallel or not 😎
This commit is contained in:
9
bin/pest
9
bin/pest
@ -35,12 +35,21 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
$argv = new ArgvInput();
|
$argv = new ArgvInput();
|
||||||
|
|
||||||
$testSuite = TestSuite::getInstance($rootPath, $argv->getParameterOption('--test-directory', 'tests'));
|
$testSuite = TestSuite::getInstance($rootPath, $argv->getParameterOption('--test-directory', 'tests'));
|
||||||
|
|
||||||
$shouldExecuteInParallel = $argv->hasParameterOption('--parallel');
|
$shouldExecuteInParallel = $argv->hasParameterOption('--parallel');
|
||||||
// Let's remove the parallel option now we've retrieved its value
|
// Let's remove the parallel option now we've retrieved its value
|
||||||
if (($parallelKey = array_search('--parallel', $_SERVER['argv'])) !== false) {
|
if (($parallelKey = array_search('--parallel', $_SERVER['argv'])) !== false) {
|
||||||
unset($_SERVER['argv'][$parallelKey]);
|
unset($_SERVER['argv'][$parallelKey]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($argv->hasParameterOption('--isInParallel')) {
|
||||||
|
$testSuite->isInParallel = true;
|
||||||
|
}
|
||||||
|
// Let's remove the parallel flag now we've retrieved its value
|
||||||
|
if (($parallelKey = array_search('--isInParallel', $_SERVER['argv'])) !== false) {
|
||||||
|
unset($_SERVER['argv'][$parallelKey]);
|
||||||
|
}
|
||||||
|
|
||||||
$isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never';
|
$isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never';
|
||||||
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
|
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);
|
||||||
|
|
||||||
|
|||||||
@ -40,10 +40,11 @@ final class PestRunnerWorker
|
|||||||
$args = array_merge(
|
$args = array_merge(
|
||||||
$args,
|
$args,
|
||||||
$this->executableTest->commandArguments(
|
$this->executableTest->commandArguments(
|
||||||
$this->getPestBinary(),
|
$this->getPestBinary($options),
|
||||||
$options->filtered(),
|
$options->filtered(),
|
||||||
$options->passthru()
|
$options->passthru()
|
||||||
)
|
),
|
||||||
|
['--isInParallel'],
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->process = new Process($args, $options->cwd(), $options->fillEnvWithTokens($token));
|
$this->process = new Process($args, $options->cwd(), $options->fillEnvWithTokens($token));
|
||||||
@ -109,15 +110,14 @@ final class PestRunnerWorker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPestBinary(): string
|
private function getPestBinary(Options $options): string
|
||||||
{
|
{
|
||||||
// Used when Pest is required using composer.
|
$paths = [
|
||||||
$vendorPath = dirname(__DIR__, 7) . '/bin/pest';
|
implode(DIRECTORY_SEPARATOR, [$options->cwd(), 'bin', 'pest']),
|
||||||
|
implode(DIRECTORY_SEPARATOR, [$options->cwd(), 'vendor', 'bin', 'pest']),
|
||||||
|
];
|
||||||
|
|
||||||
// Used when Pest maintainers are running Pest tests.
|
return file_exists($paths[0]) ? $paths[0] : $paths[1];
|
||||||
$localPath = dirname(__DIR__, 3) . '/bin/pest';
|
|
||||||
|
|
||||||
return file_exists($vendorPath) ? $vendorPath : $localPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWorkerCrashedException(?Throwable $previousException = null): WorkerCrashedException
|
public function getWorkerCrashedException(?Throwable $previousException = null): WorkerCrashedException
|
||||||
|
|||||||
@ -73,6 +73,13 @@ final class TestSuite
|
|||||||
*/
|
*/
|
||||||
public $testPath;
|
public $testPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if this test is running in parallel.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isInParallel = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds an instance of the test suite.
|
* Holds an instance of the test suite.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Pest\Support\Str;
|
use Pest\Support\Str;
|
||||||
|
use Pest\TestSuite;
|
||||||
|
|
||||||
global $globalHook;
|
global $globalHook;
|
||||||
|
|
||||||
// HACK: we have to determine our $globalHook->calls baseline. This is because
|
// HACK: we have to determine our $globalHook->calls baseline. This is because
|
||||||
// two other tests are executed before this one due to filename ordering.
|
// two other tests are executed before this one due to filename ordering.
|
||||||
$args = $_SERVER['argv'] ?? [];
|
$args = $_SERVER['argv'] ?? [];
|
||||||
$single = isset($args[1]) && Str::endsWith(__FILE__, $args[1]);
|
$single = isset($args[1]) && Str::endsWith(__FILE__, $args[1]) || TestSuite::getInstance()->isInParallel;
|
||||||
$offset = $single ? 0 : 2;
|
$offset = $single ? 0 : 2;
|
||||||
|
|
||||||
uses()->beforeAll(function () use ($globalHook, $offset) {
|
uses()->beforeAll(function () use ($globalHook, $offset) {
|
||||||
|
|||||||
Reference in New Issue
Block a user