mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 01:07:23 +01:00
refactors to use a Plugin to parse --ci option
This commit is contained in:
47
src/Plugins/Context.php
Normal file
47
src/Plugins/Context.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Context implements HandlesArguments
|
||||
{
|
||||
public const ENV_CI = 'ci';
|
||||
public const ENV_LOCAL = 'local';
|
||||
|
||||
/**
|
||||
* @var \Pest\Plugins\Context
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $env = 'local';
|
||||
|
||||
public static function getInstance(): Context
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
foreach ($arguments as $index => $argument) {
|
||||
if ($argument === '--ci') {
|
||||
unset($arguments[$index]);
|
||||
self::getInstance()->env = 'ci';
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($arguments);
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@ use Pest\Exceptions\TestAlreadyExist;
|
||||
use Pest\Exceptions\TestCaseAlreadyInUse;
|
||||
use Pest\Exceptions\TestCaseClassOrTraitNotFound;
|
||||
use Pest\Factories\TestCaseFactory;
|
||||
use Pest\Plugins\Context;
|
||||
use Pest\Support\Reflection;
|
||||
use Pest\Support\Str;
|
||||
use Pest\TestSuite;
|
||||
@ -119,7 +120,7 @@ final class TestRepository
|
||||
*/
|
||||
private function testsUsingOnly(): array
|
||||
{
|
||||
if (TestSuite::getInstance()->workingEnv === 'ci') {
|
||||
if (Context::getInstance()->env === Context::ENV_CI) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@ -73,13 +73,6 @@ final class TestSuite
|
||||
*/
|
||||
public $testPath;
|
||||
|
||||
/**
|
||||
* Holds the current working environment identifier.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $workingEnv;
|
||||
|
||||
/**
|
||||
* Holds an instance of the test suite.
|
||||
*
|
||||
@ -100,17 +93,15 @@ final class TestSuite
|
||||
|
||||
$this->rootPath = (string) realpath($rootPath);
|
||||
$this->testPath = $testPath;
|
||||
$this->workingEnv = 'local';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current instance of the test suite.
|
||||
*/
|
||||
public static function getInstance(string $rootPath = null, string $testPath = null, string $workingEnv = null): TestSuite
|
||||
public static function getInstance(string $rootPath = null, string $testPath = null): TestSuite
|
||||
{
|
||||
if (is_string($rootPath) && is_string($testPath)) {
|
||||
self::$instance = new TestSuite($rootPath, $testPath);
|
||||
self::$instance->workingEnv = $workingEnv ?? 'local';
|
||||
self::$instance = new TestSuite($rootPath, $testPath);
|
||||
|
||||
foreach (Plugin::$callables as $callable) {
|
||||
$callable();
|
||||
|
||||
Reference in New Issue
Block a user