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:
Nuno Maduro
2021-09-25 13:11:05 +01:00
committed by GitHub
7 changed files with 117 additions and 13 deletions

47
src/Plugins/Context.php Normal file
View 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);
}
}

View File

@ -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;
});

View File

@ -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;
}
/**