File tree Expand file tree Collapse file tree 5 files changed +18
-6
lines changed
Expand file tree Collapse file tree 5 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ private function createMockRequest(string $query = ''): IncomingRequest
4444 if ($ query !== '' ) {
4545 parse_str ($ query , $ get );
4646 $ request ->setGlobal ('get ' , $ get );
47+ } else {
48+ $ request ->setGlobal ('get ' , []);
4749 }
4850
4951 return $ request ;
Original file line number Diff line number Diff line change @@ -131,8 +131,8 @@ public function testLogInterpolatesPost(): void
131131
132132 Time::setTestNow ('2023-11-25 12:00:00 ' );
133133
134- $ _POST = [ ' foo ' => 'bar ' ] ;
135- $ expected = 'DEBUG - ' . Time::now ()->format ('Y-m-d ' ) . ' --> Test message $_POST: ' . print_r ($ _POST , true );
134+ service ( ' superglobals ' )-> setPost ( ' foo ', 'bar ' ) ;
135+ $ expected = 'DEBUG - ' . Time::now ()->format ('Y-m-d ' ) . ' --> Test message $_POST: ' . print_r (service ( ' superglobals ' )-> getPostArray () , true );
136136
137137 $ logger ->log ('debug ' , 'Test message {post_vars} ' );
138138
@@ -150,8 +150,8 @@ public function testLogInterpolatesGet(): void
150150
151151 Time::setTestNow ('2023-11-25 12:00:00 ' );
152152
153- $ _GET = [ ' bar ' => 'baz ' ] ;
154- $ expected = 'DEBUG - ' . Time::now ()->format ('Y-m-d ' ) . ' --> Test message $_GET: ' . print_r ($ _GET , true );
153+ service ( ' superglobals ' )-> setGet ( ' bar ', 'baz ' ) ;
154+ $ expected = 'DEBUG - ' . Time::now ()->format ('Y-m-d ' ) . ' --> Test message $_GET: ' . print_r (service ( ' superglobals ' )-> getGetArray () , true );
155155
156156 $ logger ->log ('debug ' , 'Test message {get_vars} ' );
157157
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ protected function setUp(): void
4141 {
4242 parent ::setUp ();
4343
44+ $ _SERVER = $ _GET = $ _POST = $ _COOKIE = $ _FILES = $ _REQUEST = [];
45+
4446 Services::injectMock ('superglobals ' , new Superglobals ());
4547
4648 $ this ->createPager ('/ ' );
Original file line number Diff line number Diff line change 1414namespace CodeIgniter ;
1515
1616use CodeIgniter \Test \CIUnitTestCase ;
17+ use PHPUnit \Framework \Attributes \BackupGlobals ;
1718use PHPUnit \Framework \Attributes \Group ;
1819
1920/**
2021 * @internal
2122 */
23+ #[BackupGlobals(true )]
2224#[Group('Others ' )]
2325final class SuperglobalsTest extends CIUnitTestCase
2426{
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ protected function setUp(): void
5858 $ this ->validation = new Validation ((object ) $ this ->config , service ('renderer ' ));
5959 $ this ->validation ->reset ();
6060
61- $ _FILES = [
61+ service ( ' superglobals ' )-> setFilesArray ( [
6262 'avatar ' => [
6363 'tmp_name ' => TESTPATH . '_support/Validation/uploads/phpUxc0ty ' ,
6464 'name ' => 'my-avatar.png ' ,
@@ -146,7 +146,13 @@ protected function setUp(): void
146146 400 ,
147147 ],
148148 ],
149- ];
149+ ]);
150+ }
151+
152+ protected function tearDown (): void
153+ {
154+ parent ::tearDown ();
155+ service ('superglobals ' )->setFilesArray ([]);
150156 }
151157
152158 public function testUploadedTrue (): void
You can’t perform that action at this time.
0 commit comments