fix: --watch plugin access to original arguments

This commit is contained in:
Nuno Maduro
2024-01-25 12:33:20 +00:00
parent 4febd8a11b
commit 8c57cc1731
4 changed files with 71 additions and 19 deletions

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Pest\Contracts\Plugins;
/**
* @internal
*/
interface HandlesOriginalArguments
{
/**
* Adds original arguments before the Test Suite execution.
*
* @param array<int, string> $arguments
*/
public function handleOriginalArguments(array $arguments): void;
}

View File

@ -9,6 +9,7 @@ use Pest\Exceptions\NoDirtyTestsFound;
use Pest\Plugins\Actions\CallsAddsOutput;
use Pest\Plugins\Actions\CallsBoot;
use Pest\Plugins\Actions\CallsHandleArguments;
use Pest\Plugins\Actions\CallsHandleOriginalArguments;
use Pest\Plugins\Actions\CallsShutdown;
use Pest\Support\Container;
use PHPUnit\TestRunner\TestResult\Facade;
@ -59,6 +60,11 @@ final class Kernel
->add(OutputInterface::class, $output)
->add(Container::class, $container);
$kernel = new self(
new Application(),
$output,
);
foreach (self::BOOTSTRAPPERS as $bootstrapper) {
$bootstrapper = Container::getInstance()->get($bootstrapper);
assert($bootstrapper instanceof Bootstrapper);
@ -68,11 +74,6 @@ final class Kernel
CallsBoot::execute();
$kernel = new self(
new Application(),
$output,
);
Container::getInstance()->add(self::class, $kernel);
return $kernel;
@ -81,14 +82,16 @@ final class Kernel
/**
* Runs the application, and returns the exit code.
*
* @param array<int, string> $args
* @param array<int, string> $arguments
*/
public function handle(array $args): int
public function handle(array $originalArguments, array $arguments): int
{
$args = CallsHandleArguments::execute($args);
CallsHandleOriginalArguments::execute($originalArguments);
$arguments = CallsHandleArguments::execute($arguments);
try {
$this->application->run($args);
$this->application->run($arguments);
} catch (NoDirtyTestsFound) {
$this->output->writeln([
'',

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Pest\Plugins\Actions;
use Pest\Contracts\Plugins;
use Pest\Plugin\Loader;
/**
* @internal
*/
final class CallsHandleOriginalArguments
{
/**
* Executes the Plugin action.
*
* Transform the input arguments by passing it to the relevant plugins.
*
* @param array<int, string> $argv
*/
public static function execute(array $argv): void
{
$plugins = Loader::getPlugins(Plugins\HandlesOriginalArguments::class);
/** @var Plugins\HandlesOriginalArguments $plugin */
foreach ($plugins as $plugin) {
$plugin->handleOriginalArguments($argv);
}
}
}