refactor: --ci option

This commit is contained in:
Nuno Maduro
2021-09-25 13:29:11 +01:00
parent a6e34d204c
commit 7f38de11b7
9 changed files with 99 additions and 82 deletions

View File

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

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

View File

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