mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 09:17:23 +01:00
Merge pull request #405 from def-studio/add-new-ci-option-to-pest-bin
Add new --ci option to pest bin
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,6 +120,10 @@ final class TestRepository
|
||||
*/
|
||||
private function testsUsingOnly(): array
|
||||
{
|
||||
if (Context::getInstance()->env === Context::ENV_CI) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_filter($this->state, function ($testFactory): bool {
|
||||
return $testFactory->only;
|
||||
});
|
||||
|
||||
@ -91,8 +91,8 @@ final class TestSuite
|
||||
$this->afterEach = new AfterEachRepository();
|
||||
$this->afterAll = new AfterAllRepository();
|
||||
|
||||
$this->rootPath = (string) realpath($rootPath);
|
||||
$this->testPath = $testPath;
|
||||
$this->rootPath = (string) realpath($rootPath);
|
||||
$this->testPath = $testPath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user