-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from def-studio/add-new-ci-option-to-pest-bin
Add new --ci option to pest bin
- Loading branch information
Showing
7 changed files
with
117 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use Pest\Plugins\Context; | ||
|
||
test('environment is set to CI when --ci option is used', function () { | ||
$old_env = Context::getInstance()->env; | ||
|
||
$plugin = new Context(); | ||
|
||
$plugin->handleArguments(['foo', '--ci', 'bar']); | ||
|
||
expect(Context::getInstance()->env)->toBe(Context::ENV_CI); | ||
|
||
Context::getInstance()->env = $old_env; | ||
}); | ||
|
||
test('environment is set to Local when --ci option is not used', function () { | ||
$plugin = new Context(); | ||
|
||
$plugin->handleArguments(['foo', 'bar', 'baz']); | ||
|
||
expect(Context::getInstance()->env)->toBe(Context::ENV_LOCAL); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters