mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Update plugin interfaces and instantiate container
This commit is contained in:
9
bin/pest
9
bin/pest
@ -3,8 +3,10 @@
|
||||
|
||||
use Pest\Actions\ValidatesEnvironment;
|
||||
use Pest\Console\Command;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
(static function () {
|
||||
// Used when Pest is required using composer.
|
||||
@ -24,8 +26,13 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
$rootPath = getcwd();
|
||||
|
||||
$testSuite = TestSuite::getInstance($rootPath);
|
||||
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true);
|
||||
|
||||
$container = Container::getInstance();
|
||||
$container->add(TestSuite::class, $testSuite);
|
||||
$container->add(OutputInterface::class, $output);
|
||||
|
||||
ValidatesEnvironment::in($testSuite);
|
||||
|
||||
exit((new Command($testSuite, new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true)))->run($_SERVER['argv']));
|
||||
exit($container->get(Command::class)->run($_SERVER['argv']));
|
||||
})();
|
||||
|
||||
@ -62,7 +62,7 @@ final class Command extends BaseCommand
|
||||
|
||||
/** @var HandlesArguments $plugin */
|
||||
foreach ($plugins as $plugin) {
|
||||
$argv = $plugin->handleArguments($this->testSuite, $argv);
|
||||
$argv = $plugin->handleArguments($argv);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -134,7 +134,7 @@ final class Command extends BaseCommand
|
||||
|
||||
/** @var AddsOutput $plugin */
|
||||
foreach ($plugins as $plugin) {
|
||||
$result = $plugin->addOutput($this->testSuite, $this->output, $result);
|
||||
$result = $plugin->addOutput($result);
|
||||
}
|
||||
|
||||
exit($result);
|
||||
|
||||
@ -4,9 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Contracts\Plugins;
|
||||
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -15,5 +12,5 @@ interface AddsOutput
|
||||
/**
|
||||
* Allows to add custom output after the test suite was executed.
|
||||
*/
|
||||
public function addOutput(TestSuite $testSuite, OutputInterface $output, int $testReturnCode): int;
|
||||
public function addOutput(int $testReturnCode): int;
|
||||
}
|
||||
|
||||
@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Contracts\Plugins;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -21,5 +19,5 @@ interface HandlesArguments
|
||||
*
|
||||
* @return array<int, string> the updated list of arguments
|
||||
*/
|
||||
public function handleArguments(TestSuite $testSuite, array $arguments): array;
|
||||
public function handleArguments(array $arguments): array;
|
||||
}
|
||||
|
||||
@ -13,11 +13,28 @@ use ReflectionParameter;
|
||||
*/
|
||||
final class Container
|
||||
{
|
||||
/**
|
||||
* @var self
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private $instances = [];
|
||||
|
||||
/**
|
||||
* Gets a new or already existing container.
|
||||
*/
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
static::$instance = new static();
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a dependency from the container.
|
||||
*
|
||||
|
||||
@ -143,10 +143,5 @@
|
||||
WARN Tests\Visual\Success
|
||||
s visual snapshot of test suite on success
|
||||
|
||||
<<<<<<< HEAD
|
||||
Tests: 6 skipped, 71 passed
|
||||
Time: 2.89s
|
||||
=======
|
||||
Tests: 6 skipped, 76 passed
|
||||
Time: 3.32s
|
||||
>>>>>>> 84c9078... Add basic container implementation
|
||||
Tests: 6 skipped, 78 passed
|
||||
Time: 3.37s
|
||||
|
||||
Reference in New Issue
Block a user