mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +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\Contracts\Plugins\HandlesArguments;
|
||||||
use Pest\Plugins\Actions\CallsAddsOutput;
|
use Pest\Plugins\Actions\CallsAddsOutput;
|
||||||
use Pest\Plugins\Concerns\HandleArguments;
|
use Pest\Plugins\Concerns\HandleArguments;
|
||||||
|
use Pest\Plugins\Parallel\Contracts\HandlesSubprocessArguments;
|
||||||
use Pest\Plugins\Parallel\Paratest\CleanConsoleOutput;
|
use Pest\Plugins\Parallel\Paratest\CleanConsoleOutput;
|
||||||
use Pest\Support\Arr;
|
use Pest\Support\Arr;
|
||||||
use Pest\Support\Container;
|
use Pest\Support\Container;
|
||||||
@ -24,6 +25,7 @@ final class Parallel implements HandlesArguments
|
|||||||
|
|
||||||
private const HANDLERS = [
|
private const HANDLERS = [
|
||||||
Parallel\Handlers\Parallel::class,
|
Parallel\Handlers\Parallel::class,
|
||||||
|
Parallel\Handlers\Pest::class,
|
||||||
Parallel\Handlers\Laravel::class,
|
Parallel\Handlers\Laravel::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -33,7 +35,9 @@ final class Parallel implements HandlesArguments
|
|||||||
exit($this->runTestSuiteInParallel($arguments));
|
exit($this->runTestSuiteInParallel($arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->markTestSuiteAsParallelSubProcessIfRequired();
|
if ((int) Arr::get($_SERVER, 'PARATEST') === 1) {
|
||||||
|
return $this->runSubprocessHandlers($arguments);
|
||||||
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
@ -55,9 +59,14 @@ final class Parallel implements HandlesArguments
|
|||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$handlers = array_filter(
|
||||||
|
array_map(fn ($handler) => Container::getInstance()->get($handler), self::HANDLERS),
|
||||||
|
fn ($handler) => $handler instanceof HandlesArguments,
|
||||||
|
);
|
||||||
|
|
||||||
$filteredArguments = array_reduce(
|
$filteredArguments = array_reduce(
|
||||||
self::HANDLERS,
|
$handlers,
|
||||||
fn ($arguments, $handler) => (new $handler())->handle($arguments),
|
fn ($arguments, HandlesArguments $handler) => $handler->handleArguments($arguments),
|
||||||
$arguments
|
$arguments
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -66,11 +75,18 @@ final class Parallel implements HandlesArguments
|
|||||||
return (new CallsAddsOutput())($exitCode);
|
return (new CallsAddsOutput())($exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function markTestSuiteAsParallelSubProcessIfRequired(): void
|
private function runSubprocessHandlers(array $arguments): array
|
||||||
{
|
{
|
||||||
if ((int) Arr::get($_SERVER, 'PARATEST') === 1) {
|
$handlers = array_filter(
|
||||||
$_SERVER['PEST_PARALLEL'] = 1;
|
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
|
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;
|
namespace Pest\Plugins\Parallel\Handlers;
|
||||||
|
|
||||||
|
use Composer\InstalledVersions;
|
||||||
use Illuminate\Testing\ParallelRunner;
|
use Illuminate\Testing\ParallelRunner;
|
||||||
use ParaTest\Options;
|
use ParaTest\Options;
|
||||||
use ParaTest\RunnerInterface;
|
use ParaTest\RunnerInterface;
|
||||||
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
use Pest\Plugins\Concerns\HandleArguments;
|
use Pest\Plugins\Concerns\HandleArguments;
|
||||||
|
use Pest\Plugins\Parallel\Contracts\HandlesSubprocessArguments;
|
||||||
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class Laravel
|
final class Laravel implements HandlesArguments, HandlesSubprocessArguments
|
||||||
{
|
{
|
||||||
use HandleArguments;
|
use HandleArguments;
|
||||||
|
|
||||||
public function handle(array $args): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if (! self::isALaravelApplication()) {
|
if (! self::isALaravelApplication()) {
|
||||||
return $args;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setLaravelParallelRunner();
|
$this->setLaravelParallelRunner();
|
||||||
|
|
||||||
foreach ($args as $value) {
|
foreach ($arguments as $value) {
|
||||||
if (str_starts_with((string) $value, '--runner')) {
|
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
|
private function setLaravelParallelRunner(): void
|
||||||
@ -46,8 +49,14 @@ final class Laravel
|
|||||||
|
|
||||||
private static function isALaravelApplication(): bool
|
private static function isALaravelApplication(): bool
|
||||||
{
|
{
|
||||||
return class_exists(\Illuminate\Foundation\Application::class)
|
return InstalledVersions::isInstalled('laravel/framework', false)
|
||||||
&& class_exists(\Illuminate\Testing\ParallelRunner::class)
|
|
||||||
&& ! class_exists(\Orchestra\Testbench\TestCase::class);
|
&& ! 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;
|
namespace Pest\Plugins\Parallel\Handlers;
|
||||||
|
|
||||||
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
use Pest\Plugins\Concerns\HandleArguments;
|
use Pest\Plugins\Concerns\HandleArguments;
|
||||||
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class Parallel
|
final class Parallel implements HandlesArguments
|
||||||
{
|
{
|
||||||
use HandleArguments;
|
use HandleArguments;
|
||||||
|
|
||||||
@ -23,9 +24,9 @@ final class Parallel
|
|||||||
'--no-output',
|
'--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);
|
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;
|
$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.
|
* Gets the test case factory from the given filename.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user