Skip to content

Commit 0383f06

Browse files
committed
update tests
1 parent 1b1440f commit 0383f06

41 files changed

Lines changed: 729 additions & 593 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/system/CLI/CLITest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace CodeIgniter\CLI;
1515

16+
use CodeIgniter\Config\Services;
1617
use CodeIgniter\Exceptions\RuntimeException;
18+
use CodeIgniter\Superglobals;
1719
use CodeIgniter\Test\CIUnitTestCase;
1820
use CodeIgniter\Test\PhpStreamWrapper;
1921
use CodeIgniter\Test\StreamFilterTrait;
@@ -29,6 +31,13 @@ final class CLITest extends CIUnitTestCase
2931
{
3032
use StreamFilterTrait;
3133

34+
protected function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
Services::injectMock('superglobals', new Superglobals());
39+
}
40+
3241
public function testNew(): void
3342
{
3443
$actual = new CLI();
@@ -454,12 +463,12 @@ public function testWrap(): void
454463

455464
public function testParseCommand(): void
456465
{
457-
$_SERVER['argv'] = [
466+
service('superglobals')->setServer('argv', [
458467
'ignored',
459468
'b',
460469
'c',
461-
];
462-
$_SERVER['argc'] = 3;
470+
]);
471+
service('superglobals')->setServer('argc', 3);
463472
CLI::init();
464473

465474
$this->assertNull(CLI::getSegment(3));
@@ -473,7 +482,7 @@ public function testParseCommand(): void
473482

474483
public function testParseCommandMixed(): void
475484
{
476-
$_SERVER['argv'] = [
485+
service('superglobals')->setServer('argv', [
477486
'ignored',
478487
'b',
479488
'c',
@@ -485,7 +494,7 @@ public function testParseCommandMixed(): void
485494
'--fix',
486495
'--opt-in',
487496
'sure',
488-
];
497+
]);
489498
CLI::init();
490499

491500
$this->assertNull(CLI::getSegment(7));
@@ -502,14 +511,14 @@ public function testParseCommandMixed(): void
502511

503512
public function testParseCommandOption(): void
504513
{
505-
$_SERVER['argv'] = [
514+
service('superglobals')->setServer('argv', [
506515
'ignored',
507516
'b',
508517
'c',
509518
'--parm',
510519
'pvalue',
511520
'd',
512-
];
521+
]);
513522
CLI::init();
514523

515524
$this->assertSame(['parm' => 'pvalue'], CLI::getOptions());
@@ -524,7 +533,7 @@ public function testParseCommandOption(): void
524533

525534
public function testParseCommandMultipleOptions(): void
526535
{
527-
$_SERVER['argv'] = [
536+
service('superglobals')->setServer('argv', [
528537
'ignored',
529538
'b',
530539
'c',
@@ -534,7 +543,7 @@ public function testParseCommandMultipleOptions(): void
534543
'--p2',
535544
'--p3',
536545
'value 3',
537-
];
546+
]);
538547
CLI::init();
539548

540549
$this->assertSame(['parm' => 'pvalue', 'p2' => null, 'p3' => 'value 3'], CLI::getOptions());

tests/system/CLI/ConsoleTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
use CodeIgniter\CodeIgniter;
1717
use CodeIgniter\Config\DotEnv;
18+
use CodeIgniter\Config\Services;
1819
use CodeIgniter\Events\Events;
20+
use CodeIgniter\Superglobals;
1921
use CodeIgniter\Test\CIUnitTestCase;
2022
use CodeIgniter\Test\Mock\MockCLIConfig;
2123
use CodeIgniter\Test\Mock\MockCodeIgniter;
@@ -34,12 +36,14 @@ protected function setUp(): void
3436
{
3537
parent::setUp();
3638

39+
Services::injectMock('superglobals', new Superglobals());
40+
3741
$env = new DotEnv(ROOTPATH);
3842
$env->load();
3943

4044
// Set environment values that would otherwise stop the framework from functioning during tests.
41-
if (! isset($_SERVER['app.baseURL'])) {
42-
$_SERVER['app.baseURL'] = 'http://example.com/';
45+
if (service('superglobals')->server('app.baseURL') === null) {
46+
service('superglobals')->setServer('app.baseURL', 'http://example.com/');
4347
}
4448

4549
$this->app = new MockCodeIgniter(new MockCLIConfig());
@@ -173,8 +177,8 @@ public function testHelpArgumentAndHelpOptionCombined(): void
173177
*/
174178
protected function initCLI(...$command): void
175179
{
176-
$_SERVER['argv'] = ['spark', ...$command];
177-
$_SERVER['argc'] = count($_SERVER['argv']);
180+
service('superglobals')->setServer('argv', ['spark', ...$command]);
181+
service('superglobals')->setServer('argc', count(service('superglobals')->server('argv')));
178182

179183
CLI::init();
180184
}

tests/system/Cache/ResponseCacheTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
namespace CodeIgniter\Cache;
1515

16+
use CodeIgniter\Config\Services;
1617
use CodeIgniter\Exceptions\RuntimeException;
1718
use CodeIgniter\HTTP\CLIRequest;
1819
use CodeIgniter\HTTP\IncomingRequest;
1920
use CodeIgniter\HTTP\Response;
2021
use CodeIgniter\HTTP\ResponseInterface;
2122
use CodeIgniter\HTTP\SiteURI;
2223
use CodeIgniter\HTTP\UserAgent;
24+
use CodeIgniter\Superglobals;
2325
use CodeIgniter\Test\CIUnitTestCase;
2426
use CodeIgniter\Test\Mock\MockCache;
2527
use Config\App;
@@ -35,6 +37,13 @@
3537
#[Group('Others')]
3638
final class ResponseCacheTest extends CIUnitTestCase
3739
{
40+
protected function setUp(): void
41+
{
42+
parent::setUp();
43+
44+
Services::injectMock('superglobals', new Superglobals());
45+
}
46+
3847
/**
3948
* @param array<string, string> $query
4049
*/
@@ -58,7 +67,7 @@ private function createIncomingRequest(string $uri = '', array $query = [], App
5867
*/
5968
private function createCLIRequest(array $params = [], App $app = new App()): CLIRequest
6069
{
61-
$_SERVER['argv'] = ['public/index.php', ...$params];
70+
service('superglobals')->setServer('argv', ['public/index.php', ...$params]);
6271

6372
$superglobals = service('superglobals');
6473
$superglobals->setServer('SCRIPT_NAME', 'public/index.php');

0 commit comments

Comments
 (0)