Skip to content

Commit 84b4a31

Browse files
committed
feat: add Superglobals::setGet()
1 parent 6b3dd7a commit 84b4a31

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

system/Superglobals.php

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public function get(string $key)
4646
return $this->get[$key] ?? null;
4747
}
4848

49+
public function setGet(string $key, string $value): void
50+
{
51+
$this->get[$key] = $value;
52+
$_GET[$key] = $value;
53+
}
54+
4955
public function setGetArray(array $array): void
5056
{
5157
$this->get = $array;

tests/system/SuperglobalsTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter;
13+
14+
use CodeIgniter\Test\CIUnitTestCase;
15+
16+
/**
17+
* @internal
18+
*
19+
* @group Others
20+
*/
21+
final class SuperglobalsTest extends CIUnitTestCase
22+
{
23+
public function testSetGet()
24+
{
25+
$globals = new Superglobals([], []);
26+
27+
$globals->setGet('test', 'value1');
28+
29+
$this->assertSame('value1', $globals->get('test'));
30+
}
31+
}

0 commit comments

Comments
 (0)