Skip to content

Commit 745a93d

Browse files
committed
test: update tests
1 parent 2dd6467 commit 745a93d

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

tests/system/API/ResponseTraitTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,25 @@ public function testFormatByRequestNegotiateIfFormatIsNotJsonOrXML()
542542
'negotiateLocale' => false,
543543
'supportedLocales' => ['en'],
544544
'CSPEnabled' => false,
545-
'cookiePrefix' => '',
546-
'cookieDomain' => '',
547-
'cookiePath' => '/',
548-
'cookieSecure' => false,
549-
'cookieHTTPOnly' => false,
550545
'proxyIPs' => [],
551-
'cookieSameSite' => 'Lax',
552546
] as $key => $value) {
553547
$config->{$key} = $value;
554548
}
555549

550+
$cookie = new Cookie();
551+
552+
foreach ([
553+
'prefix' => '',
554+
'domain' => '',
555+
'path' => '/',
556+
'secure' => false,
557+
'httponly' => false,
558+
'samesite' => 'Lax',
559+
] as $key => $value) {
560+
$cookie->{$key} = $value;
561+
}
562+
Factories::injectMock('config', 'Cookie', $cookie);
563+
556564
$request = new MockIncomingRequest($config, new URI($config->baseURL), null, new UserAgent());
557565
$response = new MockResponse($config);
558566

tests/system/CommonFunctionsTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter;
1313

1414
use CodeIgniter\Config\BaseService;
15+
use CodeIgniter\Config\Factories;
1516
use CodeIgniter\HTTP\CLIRequest;
1617
use CodeIgniter\HTTP\IncomingRequest;
1718
use CodeIgniter\HTTP\RedirectResponse;
@@ -28,6 +29,7 @@
2829
use CodeIgniter\Test\Mock\MockSession;
2930
use CodeIgniter\Test\TestLogger;
3031
use Config\App;
32+
use Config\Cookie;
3133
use Config\Logger;
3234
use Config\Modules;
3335
use Config\Services;
@@ -511,6 +513,8 @@ public function testSlashItemThrowsErrorOnNonStringableItem()
511513

512514
protected function injectSessionMock()
513515
{
516+
$appConfig = new App();
517+
514518
$defaults = [
515519
'sessionDriver' => FileHandler::class,
516520
'sessionCookieName' => 'ci_session',
@@ -519,19 +523,25 @@ protected function injectSessionMock()
519523
'sessionMatchIP' => false,
520524
'sessionTimeToUpdate' => 300,
521525
'sessionRegenerateDestroy' => false,
522-
'cookieDomain' => '',
523-
'cookiePrefix' => '',
524-
'cookiePath' => '/',
525-
'cookieSecure' => false,
526-
'cookieSameSite' => 'Lax',
527526
];
528527

529-
$appConfig = new App();
530-
531528
foreach ($defaults as $key => $config) {
532529
$appConfig->{$key} = $config;
533530
}
534531

532+
$cookie = new Cookie();
533+
534+
foreach ([
535+
'prefix' => '',
536+
'domain' => '',
537+
'path' => '/',
538+
'secure' => false,
539+
'samesite' => 'Lax',
540+
] as $key => $value) {
541+
$cookie->{$key} = $value;
542+
}
543+
Factories::injectMock('config', 'Cookie', $cookie);
544+
535545
$session = new MockSession(new FileHandler($appConfig, '127.0.0.1'), $appConfig);
536546
$session->setLogger(new TestLogger(new Logger()));
537547
BaseService::injectMock('session', $session);

tests/system/Security/SecurityCSRFSessionRandomizeTokenTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use CodeIgniter\Test\Mock\MockSession;
2727
use CodeIgniter\Test\TestLogger;
2828
use Config\App as AppConfig;
29+
use Config\Cookie;
2930
use Config\Logger as LoggerConfig;
3031
use Config\Security as SecurityConfig;
3132

@@ -75,20 +76,28 @@ private function createSession($options = []): Session
7576
'sessionMatchIP' => false,
7677
'sessionTimeToUpdate' => 300,
7778
'sessionRegenerateDestroy' => false,
78-
'cookieDomain' => '',
79-
'cookiePrefix' => '',
80-
'cookiePath' => '/',
81-
'cookieSecure' => false,
82-
'cookieSameSite' => 'Lax',
8379
];
80+
$config = array_merge($defaults, $options);
8481

85-
$config = array_merge($defaults, $options);
8682
$appConfig = new AppConfig();
8783

8884
foreach ($config as $key => $c) {
8985
$appConfig->{$key} = $c;
9086
}
9187

88+
$cookie = new Cookie();
89+
90+
foreach ([
91+
'prefix' => '',
92+
'domain' => '',
93+
'path' => '/',
94+
'secure' => false,
95+
'samesite' => 'Lax',
96+
] as $key => $value) {
97+
$cookie->{$key} = $value;
98+
}
99+
Factories::injectMock('config', 'Cookie', $cookie);
100+
92101
$session = new MockSession(new ArrayHandler($appConfig, '127.0.0.1'), $appConfig);
93102
$session->setLogger(new TestLogger(new LoggerConfig()));
94103

tests/system/Security/SecurityCSRFSessionTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use CodeIgniter\Test\Mock\MockSession;
2626
use CodeIgniter\Test\TestLogger;
2727
use Config\App as AppConfig;
28+
use Config\Cookie;
2829
use Config\Logger as LoggerConfig;
2930
use Config\Security as SecurityConfig;
3031

@@ -68,20 +69,28 @@ private function createSession($options = []): Session
6869
'sessionMatchIP' => false,
6970
'sessionTimeToUpdate' => 300,
7071
'sessionRegenerateDestroy' => false,
71-
'cookieDomain' => '',
72-
'cookiePrefix' => '',
73-
'cookiePath' => '/',
74-
'cookieSecure' => false,
75-
'cookieSameSite' => 'Lax',
7672
];
73+
$config = array_merge($defaults, $options);
7774

78-
$config = array_merge($defaults, $options);
7975
$appConfig = new AppConfig();
8076

8177
foreach ($config as $key => $c) {
8278
$appConfig->{$key} = $c;
8379
}
8480

81+
$cookie = new Cookie();
82+
83+
foreach ([
84+
'prefix' => '',
85+
'domain' => '',
86+
'path' => '/',
87+
'secure' => false,
88+
'samesite' => 'Lax',
89+
] as $key => $value) {
90+
$cookie->{$key} = $value;
91+
}
92+
Factories::injectMock('config', 'Cookie', $cookie);
93+
8594
$session = new MockSession(new ArrayHandler($appConfig, '127.0.0.1'), $appConfig);
8695
$session->setLogger(new TestLogger(new LoggerConfig()));
8796

0 commit comments

Comments
 (0)