Skip to content

Commit d4a8a1d

Browse files
committed
test: update failed tests
1 parent 97eb3a7 commit d4a8a1d

2 files changed

Lines changed: 53 additions & 34 deletions

File tree

tests/system/Session/Handlers/Database/MySQLiHandlerTest.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace CodeIgniter\Session\Handlers\Database;
1313

14+
use CodeIgniter\Config\Factories;
1415
use CodeIgniter\Session\Handlers\DatabaseHandler;
1516
use Config\App as AppConfig;
1617
use Config\Database as DatabaseConfig;
18+
use Config\Session as SessionConfig;
1719

1820
/**
1921
* @group DatabaseLive
@@ -34,26 +36,34 @@ protected function setUp(): void
3436
protected function getInstance($options = [])
3537
{
3638
$defaults = [
37-
'sessionDriver' => DatabaseHandler::class,
38-
'sessionCookieName' => 'ci_session',
39-
'sessionExpiration' => 7200,
40-
'sessionSavePath' => 'ci_sessions',
41-
'sessionMatchIP' => false,
42-
'sessionTimeToUpdate' => 300,
43-
'sessionRegenerateDestroy' => false,
44-
'cookieDomain' => '',
45-
'cookiePrefix' => '',
46-
'cookiePath' => '/',
47-
'cookieSecure' => false,
48-
'cookieSameSite' => 'Lax',
39+
'cookieDomain' => '',
40+
'cookiePrefix' => '',
41+
'cookiePath' => '/',
42+
'cookieSecure' => false,
43+
'cookieSameSite' => 'Lax',
4944
];
50-
51-
$config = array_merge($defaults, $options);
5245
$appConfig = new AppConfig();
5346

54-
foreach ($config as $key => $c) {
55-
$appConfig->{$key} = $c;
47+
foreach ($defaults as $key => $value) {
48+
$appConfig->{$key} = $value;
49+
}
50+
51+
$defaults = [
52+
'driver' => DatabaseHandler::class,
53+
'cookieName' => 'ci_session',
54+
'expiration' => 7200,
55+
'savePath' => 'ci_sessions',
56+
'matchIP' => false,
57+
'timeToUpdate' => 300,
58+
'regenerateDestroy' => false,
59+
];
60+
$sessionConfig = new SessionConfig();
61+
$config = array_merge($defaults, $options);
62+
63+
foreach ($config as $key => $value) {
64+
$sessionConfig->{$key} = $value;
5665
}
66+
Factories::injectMock('config', 'Session', $sessionConfig);
5767

5868
return new MySQLiHandler($appConfig, '127.0.0.1');
5969
}

tests/system/Session/SessionTest.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Config\App as AppConfig;
2121
use Config\Cookie as CookieConfig;
2222
use Config\Logger as LoggerConfig;
23+
use Config\Session as SessionConfig;
2324

2425
/**
2526
* @runTestsInSeparateProcesses
@@ -43,26 +44,34 @@ protected function setUp(): void
4344
protected function getInstance($options = [])
4445
{
4546
$defaults = [
46-
'sessionDriver' => FileHandler::class,
47-
'sessionCookieName' => 'ci_session',
48-
'sessionExpiration' => 7200,
49-
'sessionSavePath' => '',
50-
'sessionMatchIP' => false,
51-
'sessionTimeToUpdate' => 300,
52-
'sessionRegenerateDestroy' => false,
53-
'cookieDomain' => '',
54-
'cookiePrefix' => '',
55-
'cookiePath' => '/',
56-
'cookieSecure' => false,
57-
'cookieSameSite' => 'Lax',
47+
'cookieDomain' => '',
48+
'cookiePrefix' => '',
49+
'cookiePath' => '/',
50+
'cookieSecure' => false,
51+
'cookieSameSite' => 'Lax',
5852
];
59-
60-
$config = array_merge($defaults, $options);
6153
$appConfig = new AppConfig();
6254

63-
foreach ($config as $key => $c) {
64-
$appConfig->{$key} = $c;
55+
foreach ($defaults as $key => $value) {
56+
$appConfig->{$key} = $value;
57+
}
58+
59+
$defaults = [
60+
'driver' => FileHandler::class,
61+
'cookieName' => 'ci_session',
62+
'expiration' => 7200,
63+
'savePath' => '',
64+
'matchIP' => false,
65+
'timeToUpdate' => 300,
66+
'regenerateDestroy' => false,
67+
];
68+
$sessionConfig = new SessionConfig();
69+
$config = array_merge($defaults, $options);
70+
71+
foreach ($config as $key => $value) {
72+
$sessionConfig->{$key} = $value;
6573
}
74+
Factories::injectMock('config', 'Session', $sessionConfig);
6675

6776
$session = new MockSession(new FileHandler($appConfig, '127.0.0.1'), $appConfig);
6877
$session->setLogger(new TestLogger(new LoggerConfig()));
@@ -626,7 +635,7 @@ public function testInvalidSameSite()
626635

627636
public function testExpires()
628637
{
629-
$session = $this->getInstance(['sessionExpiration' => 8000]);
638+
$session = $this->getInstance(['expiration' => 8000]);
630639
$session->start();
631640

632641
$cookies = $session->cookies;
@@ -636,7 +645,7 @@ public function testExpires()
636645

637646
public function testExpiresOnClose()
638647
{
639-
$session = $this->getInstance(['sessionExpiration' => 0]);
648+
$session = $this->getInstance(['expiration' => 0]);
640649
$session->start();
641650

642651
$cookies = $session->cookies;

0 commit comments

Comments
 (0)