1313
1414namespace CodeIgniter \CLI ;
1515
16+ use CodeIgniter \Config \Services ;
1617use CodeIgniter \Exceptions \RuntimeException ;
18+ use CodeIgniter \Superglobals ;
1719use CodeIgniter \Test \CIUnitTestCase ;
1820use CodeIgniter \Test \PhpStreamWrapper ;
1921use 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 ());
0 commit comments