mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
refactor: --ci option
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
<?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);
|
||||
});
|
||||
23
tests/Unit/Plugins/Environment.php
Normal file
23
tests/Unit/Plugins/Environment.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Pest\Plugins\Environment;
|
||||
|
||||
test('environment is set to CI when --ci option is used', function () {
|
||||
$previousName = Environment::name();
|
||||
|
||||
$plugin = new Environment();
|
||||
|
||||
$plugin->handleArguments(['foo', '--ci', 'bar']);
|
||||
|
||||
expect(Environment::name())->toBe(Environment::CI);
|
||||
|
||||
Environment::name($previousName);
|
||||
});
|
||||
|
||||
test('environment is set to Local when --ci option is not used', function () {
|
||||
$plugin = new Environment();
|
||||
|
||||
$plugin->handleArguments(['foo', 'bar', 'baz']);
|
||||
|
||||
expect(Environment::name())->toBe(Environment::LOCAL);
|
||||
});
|
||||
@ -3,7 +3,7 @@
|
||||
use Pest\Exceptions\DatasetMissing;
|
||||
use Pest\Exceptions\TestAlreadyExist;
|
||||
use Pest\Factories\TestCaseFactory;
|
||||
use Pest\Plugins\Context;
|
||||
use Pest\Plugins\Environment;
|
||||
use Pest\TestSuite;
|
||||
|
||||
it('does not allow to add the same test description twice', function () {
|
||||
@ -38,7 +38,7 @@ it('can return an array of all test suite filenames', function () {
|
||||
});
|
||||
|
||||
it('can filter the test suite filenames to those with the only method', function () {
|
||||
$testSuite = TestSuite::getInstance(getcwd(), 'tests');
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
$test = function () {};
|
||||
|
||||
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
|
||||
@ -53,8 +53,8 @@ it('can filter the test suite filenames to those with the only method', function
|
||||
});
|
||||
|
||||
it('does not filter the test suite filenames to those with the only method when working in CI pipeline', function () {
|
||||
$old_env = Context::getInstance()->env;
|
||||
Context::getInstance()->env = Context::ENV_CI;
|
||||
$previousEnvironment = Environment::name();
|
||||
Environment::name(Environment::CI);
|
||||
$testSuite = TestSuite::getInstance(getcwd(), 'tests');
|
||||
|
||||
$test = function () {};
|
||||
@ -70,5 +70,5 @@ it('does not filter the test suite filenames to those with the only method when
|
||||
'Baz/Bar/Boo.php',
|
||||
]);
|
||||
|
||||
Context::getInstance()->env = $old_env;
|
||||
Environment::name($previousEnvironment);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user