mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
refacto: bootstrappers and parallel minor stuff
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -13,7 +13,7 @@ use Pest\Contracts\Bootstrapper;
|
||||
final class BootExceptionHandler implements Bootstrapper
|
||||
{
|
||||
/**
|
||||
* Boots the Exception Handler.
|
||||
* Boots the "Collision" exception handler.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
@ -19,7 +19,7 @@ use SebastianBergmann\FileIterator\Facade as PhpUnitFileIterator;
|
||||
final class BootFiles implements Bootstrapper
|
||||
{
|
||||
/**
|
||||
* The Pest convention.
|
||||
* The structure of the tests directory.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
@ -32,7 +32,7 @@ final class BootFiles implements Bootstrapper
|
||||
];
|
||||
|
||||
/**
|
||||
* Boots the Subscribers.
|
||||
* Boots the structure of the tests directory.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
@ -23,7 +23,7 @@ final class BootOverrides implements Bootstrapper
|
||||
];
|
||||
|
||||
/**
|
||||
* Boots the Subscribers.
|
||||
* Boots the list of files to be overridden.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@ use PHPUnit\Event\Subscriber;
|
||||
final class BootSubscribers implements Bootstrapper
|
||||
{
|
||||
/**
|
||||
* The Kernel subscribers.
|
||||
* The list of Subscribers.
|
||||
*
|
||||
* @var array<int, class-string<Subscriber>>
|
||||
*/
|
||||
@ -27,7 +27,7 @@ final class BootSubscribers implements Bootstrapper
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates a new Subscriber instance.
|
||||
* Creates a new instance of the Boot Subscribers.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Container $container,
|
||||
@ -35,7 +35,7 @@ final class BootSubscribers implements Bootstrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Boots the Subscribers.
|
||||
* Boots the list of Subscribers.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
@ -13,6 +13,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
final class BootView implements Bootstrapper
|
||||
{
|
||||
/**
|
||||
* Creates a new instance of the Boot View.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly OutputInterface $output
|
||||
) {
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Parallel\Handlers;
|
||||
|
||||
use Closure;
|
||||
use Composer\InstalledVersions;
|
||||
use Illuminate\Testing\ParallelRunner;
|
||||
use ParaTest\Options;
|
||||
@ -22,38 +23,53 @@ final class Laravel implements HandlesArguments
|
||||
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (! self::isALaravelApplication()) {
|
||||
return $arguments;
|
||||
}
|
||||
return self::whenUsingLaravel($arguments, function (array $arguments): array {
|
||||
$this->ensureRunnerIsResolvable();
|
||||
|
||||
$this->setLaravelParallelRunner();
|
||||
$arguments = $this->ensureEnvironmentVariables($arguments);
|
||||
|
||||
$arguments = $this->setEnvironmentVariables($arguments);
|
||||
|
||||
return $this->useLaravelRunner($arguments);
|
||||
return $this->ensureRunner($arguments);
|
||||
});
|
||||
}
|
||||
|
||||
private function setLaravelParallelRunner(): void
|
||||
/**
|
||||
* Executes the given closure when running Laravel.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @param CLosure(array<int, string>): array<int, string> $closure
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private static function whenUsingLaravel(array $arguments, Closure $closure): array
|
||||
{
|
||||
$isLaravelApplication = InstalledVersions::isInstalled('laravel/framework', false);
|
||||
$isLaravelPackage = class_exists(\Orchestra\Testbench\TestCase::class);
|
||||
if ($isLaravelApplication) {
|
||||
return $closure($arguments);
|
||||
}
|
||||
if ($isLaravelPackage) {
|
||||
return $closure($arguments);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the runner is resolvable.
|
||||
*/
|
||||
private function ensureRunnerIsResolvable(): void
|
||||
{
|
||||
ParallelRunner::resolveRunnerUsing( // @phpstan-ignore-line
|
||||
fn (Options $options, OutputInterface $output): RunnerInterface => new WrapperRunner($options, $output)
|
||||
);
|
||||
}
|
||||
|
||||
private static function isALaravelApplication(): bool
|
||||
{
|
||||
if (! InstalledVersions::isInstalled('laravel/framework', false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! class_exists(\Orchestra\Testbench\TestCase::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the environment variables are set.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function setEnvironmentVariables(array $arguments): array
|
||||
private function ensureEnvironmentVariables(array $arguments): array
|
||||
{
|
||||
$_ENV['LARAVEL_PARALLEL_TESTING'] = 1;
|
||||
|
||||
@ -71,10 +87,12 @@ final class Laravel implements HandlesArguments
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the runner is set.
|
||||
*
|
||||
* @param array<int, string> $arguments
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function useLaravelRunner(array $arguments): array
|
||||
private function ensureRunner(array $arguments): array
|
||||
{
|
||||
foreach ($arguments as $value) {
|
||||
if (str_starts_with($value, '--runner')) {
|
||||
|
||||
Reference in New Issue
Block a user