mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
WIP
This commit is contained in:
committed by
Nuno Maduro
parent
aff11486b2
commit
2561d47bb5
@ -8,6 +8,7 @@ use ParaTest\ParaTestCommand;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Actions\CallsAddsOutput;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use Pest\Plugins\Parallel\Contracts\HandlesSubprocessArguments;
|
||||
use Pest\Plugins\Parallel\Paratest\CleanConsoleOutput;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\Container;
|
||||
@ -24,6 +25,7 @@ final class Parallel implements HandlesArguments
|
||||
|
||||
private const HANDLERS = [
|
||||
Parallel\Handlers\Parallel::class,
|
||||
Parallel\Handlers\Pest::class,
|
||||
Parallel\Handlers\Laravel::class,
|
||||
];
|
||||
|
||||
@ -33,7 +35,9 @@ final class Parallel implements HandlesArguments
|
||||
exit($this->runTestSuiteInParallel($arguments));
|
||||
}
|
||||
|
||||
$this->markTestSuiteAsParallelSubProcessIfRequired();
|
||||
if ((int) Arr::get($_SERVER, 'PARATEST') === 1) {
|
||||
return $this->runSubprocessHandlers($arguments);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
@ -55,9 +59,14 @@ final class Parallel implements HandlesArguments
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$handlers = array_filter(
|
||||
array_map(fn ($handler) => Container::getInstance()->get($handler), self::HANDLERS),
|
||||
fn ($handler) => $handler instanceof HandlesArguments,
|
||||
);
|
||||
|
||||
$filteredArguments = array_reduce(
|
||||
self::HANDLERS,
|
||||
fn ($arguments, $handler) => (new $handler())->handle($arguments),
|
||||
$handlers,
|
||||
fn ($arguments, HandlesArguments $handler) => $handler->handleArguments($arguments),
|
||||
$arguments
|
||||
);
|
||||
|
||||
@ -66,11 +75,18 @@ final class Parallel implements HandlesArguments
|
||||
return (new CallsAddsOutput())($exitCode);
|
||||
}
|
||||
|
||||
private function markTestSuiteAsParallelSubProcessIfRequired(): void
|
||||
private function runSubprocessHandlers(array $arguments): array
|
||||
{
|
||||
if ((int) Arr::get($_SERVER, 'PARATEST') === 1) {
|
||||
$_SERVER['PEST_PARALLEL'] = 1;
|
||||
}
|
||||
$handlers = array_filter(
|
||||
array_map(fn ($handler) => Container::getInstance()->get($handler), self::HANDLERS),
|
||||
fn ($handler) => $handler instanceof HandlesSubprocessArguments,
|
||||
);
|
||||
|
||||
return array_reduce(
|
||||
$handlers,
|
||||
fn ($arguments, HandlesSubprocessArguments $handler) => $handler->handleSubprocessArguments($arguments),
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
|
||||
private function askUserToInstallParatest(): void
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Parallel\Contracts;
|
||||
|
||||
interface HandlesSubprocessArguments
|
||||
{
|
||||
public function handleSubprocessArguments(array $arguments): array;
|
||||
}
|
||||
@ -4,35 +4,38 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Parallel\Handlers;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Illuminate\Testing\ParallelRunner;
|
||||
use ParaTest\Options;
|
||||
use ParaTest\RunnerInterface;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use Pest\Plugins\Parallel\Contracts\HandlesSubprocessArguments;
|
||||
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Laravel
|
||||
final class Laravel implements HandlesArguments, HandlesSubprocessArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
public function handle(array $args): array
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (! self::isALaravelApplication()) {
|
||||
return $args;
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$this->setLaravelParallelRunner();
|
||||
|
||||
foreach ($args as $value) {
|
||||
foreach ($arguments as $value) {
|
||||
if (str_starts_with((string) $value, '--runner')) {
|
||||
$args = $this->popArgument($value, $args);
|
||||
$arguments = $this->popArgument($value, $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->pushArgument('--runner=\Illuminate\Testing\ParallelRunner', $args);
|
||||
return $this->pushArgument('--runner=\Illuminate\Testing\ParallelRunner', $arguments);
|
||||
}
|
||||
|
||||
private function setLaravelParallelRunner(): void
|
||||
@ -46,8 +49,14 @@ final class Laravel
|
||||
|
||||
private static function isALaravelApplication(): bool
|
||||
{
|
||||
return class_exists(\Illuminate\Foundation\Application::class)
|
||||
&& class_exists(\Illuminate\Testing\ParallelRunner::class)
|
||||
return InstalledVersions::isInstalled('laravel/framework', false)
|
||||
&& ! class_exists(\Orchestra\Testbench\TestCase::class);
|
||||
}
|
||||
|
||||
public function handleSubprocessArguments(array $arguments): array
|
||||
{
|
||||
putenv('LARAVEL_PARALLEL_TESTING=1');
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,13 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Parallel\Handlers;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Parallel
|
||||
final class Parallel implements HandlesArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
@ -23,9 +24,9 @@ final class Parallel
|
||||
'--no-output',
|
||||
];
|
||||
|
||||
public function handle(array $args): array
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
$args = array_reduce(self::ARGS_TO_REMOVE, fn ($args, $arg): array => $this->popArgument($arg, $args), $args);
|
||||
$args = array_reduce(self::ARGS_TO_REMOVE, fn ($args, $arg): array => $this->popArgument($arg, $args), $arguments);
|
||||
|
||||
return $this->pushArgument('--runner='.WrapperRunner::class, $args);
|
||||
}
|
||||
|
||||
20
src/Plugins/Parallel/Handlers/Pest.php
Normal file
20
src/Plugins/Parallel/Handlers/Pest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Pest\Plugins\Parallel\Handlers;
|
||||
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use Pest\Plugins\Parallel\Contracts\HandlesSubprocessArguments;
|
||||
use Pest\TestCaseMethodFilters\TodoTestCaseFilter;
|
||||
use Pest\TestSuite;
|
||||
|
||||
final class Pest implements HandlesSubprocessArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
public function handleSubprocessArguments(array $arguments): array
|
||||
{
|
||||
$_SERVER['PEST_PARALLEL'] = '1';
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
@ -112,6 +112,20 @@ final class TestRepository
|
||||
$this->testCaseMethodFilters[] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<TestCaseMethodFilter> $filter
|
||||
*/
|
||||
public function hasTestCaseMethodFilter(string $filter): bool
|
||||
{
|
||||
foreach ($this->testCaseMethodFilters as $testCaseMethodFilter) {
|
||||
if ($testCaseMethodFilter instanceof $filter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test case factory from the given filename.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user