Skip to content

Commit 778c412

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

4 files changed

Lines changed: 65 additions & 76 deletions

File tree

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

Lines changed: 15 additions & 18 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,27 +36,22 @@ 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+
'driver' => DatabaseHandler::class,
40+
'cookieName' => 'ci_session',
41+
'expiration' => 7200,
42+
'savePath' => 'ci_sessions',
43+
'matchIP' => false,
44+
'timeToUpdate' => 300,
45+
'regenerateDestroy' => false,
4946
];
47+
$sessionConfig = new SessionConfig();
48+
$config = array_merge($defaults, $options);
5049

51-
$config = array_merge($defaults, $options);
52-
$appConfig = new AppConfig();
53-
54-
foreach ($config as $key => $c) {
55-
$appConfig->{$key} = $c;
50+
foreach ($config as $key => $value) {
51+
$sessionConfig->{$key} = $value;
5652
}
53+
Factories::injectMock('config', 'Session', $sessionConfig);
5754

58-
return new MySQLiHandler($appConfig, '127.0.0.1');
55+
return new MySQLiHandler(new AppConfig(), '127.0.0.1');
5956
}
6057
}

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

Lines changed: 15 additions & 18 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,27 +36,22 @@ 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+
'driver' => DatabaseHandler::class,
40+
'cookieName' => 'ci_session',
41+
'expiration' => 7200,
42+
'savePath' => 'ci_sessions',
43+
'matchIP' => false,
44+
'timeToUpdate' => 300,
45+
'regenerateDestroy' => false,
4946
];
47+
$sessionConfig = new SessionConfig();
48+
$config = array_merge($defaults, $options);
5049

51-
$config = array_merge($defaults, $options);
52-
$appConfig = new AppConfig();
53-
54-
foreach ($config as $key => $c) {
55-
$appConfig->{$key} = $c;
50+
foreach ($config as $key => $value) {
51+
$sessionConfig->{$key} = $value;
5652
}
53+
Factories::injectMock('config', 'Session', $sessionConfig);
5754

58-
return new PostgreHandler($appConfig, '127.0.0.1');
55+
return new PostgreHandler(new AppConfig(), '127.0.0.1');
5956
}
6057
}

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

Lines changed: 18 additions & 21 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\RedisHandler;
1516
use CodeIgniter\Test\CIUnitTestCase;
1617
use Config\App as AppConfig;
18+
use Config\Session as SessionConfig;
1719
use Redis;
1820

1921
/**
@@ -29,37 +31,32 @@ final class RedisHandlerTest extends CIUnitTestCase
2931
private string $sessionSavePath = 'tcp://127.0.0.1:6379';
3032
private string $userIpAddress = '127.0.0.1';
3133

32-
private function getInstance($options = [])
34+
protected function getInstance($options = [])
3335
{
3436
$defaults = [
35-
'sessionDriver' => RedisHandler::class,
36-
'sessionCookieName' => $this->sessionName,
37-
'sessionExpiration' => 7200,
38-
'sessionSavePath' => $this->sessionSavePath,
39-
'sessionMatchIP' => false,
40-
'sessionTimeToUpdate' => 300,
41-
'sessionRegenerateDestroy' => false,
42-
'cookieDomain' => '',
43-
'cookiePrefix' => '',
44-
'cookiePath' => '/',
45-
'cookieSecure' => false,
46-
'cookieSameSite' => 'Lax',
37+
'driver' => RedisHandler::class,
38+
'cookieName' => $this->sessionName,
39+
'expiration' => 7200,
40+
'savePath' => $this->sessionSavePath,
41+
'matchIP' => false,
42+
'timeToUpdate' => 300,
43+
'regenerateDestroy' => false,
4744
];
45+
$sessionConfig = new SessionConfig();
46+
$config = array_merge($defaults, $options);
4847

49-
$config = array_merge($defaults, $options);
50-
$appConfig = new AppConfig();
51-
52-
foreach ($config as $key => $c) {
53-
$appConfig->{$key} = $c;
48+
foreach ($config as $key => $value) {
49+
$sessionConfig->{$key} = $value;
5450
}
51+
Factories::injectMock('config', 'Session', $sessionConfig);
5552

56-
return new RedisHandler($appConfig, $this->userIpAddress);
53+
return new RedisHandler(new AppConfig(), $this->userIpAddress);
5754
}
5855

5956
public function testSavePathTimeoutFloat()
6057
{
6158
$handler = $this->getInstance(
62-
['sessionSavePath' => 'tcp://127.0.0.1:6379?timeout=2.5']
59+
['savePath' => 'tcp://127.0.0.1:6379?timeout=2.5']
6360
);
6461

6562
$savePath = $this->getPrivateProperty($handler, 'savePath');
@@ -70,7 +67,7 @@ public function testSavePathTimeoutFloat()
7067
public function testSavePathTimeoutInt()
7168
{
7269
$handler = $this->getInstance(
73-
['sessionSavePath' => 'tcp://127.0.0.1:6379?timeout=10']
70+
['savePath' => 'tcp://127.0.0.1:6379?timeout=10']
7471
);
7572

7673
$savePath = $this->getPrivateProperty($handler, 'savePath');

tests/system/Session/SessionTest.php

Lines changed: 17 additions & 19 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
@@ -42,27 +43,24 @@ protected function setUp(): void
4243

4344
protected function getInstance($options = [])
4445
{
46+
$appConfig = new AppConfig();
47+
4548
$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',
49+
'driver' => FileHandler::class,
50+
'cookieName' => 'ci_session',
51+
'expiration' => 7200,
52+
'savePath' => '',
53+
'matchIP' => false,
54+
'timeToUpdate' => 300,
55+
'regenerateDestroy' => false,
5856
];
57+
$sessionConfig = new SessionConfig();
58+
$config = array_merge($defaults, $options);
5959

60-
$config = array_merge($defaults, $options);
61-
$appConfig = new AppConfig();
62-
63-
foreach ($config as $key => $c) {
64-
$appConfig->{$key} = $c;
60+
foreach ($config as $key => $value) {
61+
$sessionConfig->{$key} = $value;
6562
}
63+
Factories::injectMock('config', 'Session', $sessionConfig);
6664

6765
$session = new MockSession(new FileHandler($appConfig, '127.0.0.1'), $appConfig);
6866
$session->setLogger(new TestLogger(new LoggerConfig()));
@@ -626,7 +624,7 @@ public function testInvalidSameSite()
626624

627625
public function testExpires()
628626
{
629-
$session = $this->getInstance(['sessionExpiration' => 8000]);
627+
$session = $this->getInstance(['expiration' => 8000]);
630628
$session->start();
631629

632630
$cookies = $session->cookies;
@@ -636,7 +634,7 @@ public function testExpires()
636634

637635
public function testExpiresOnClose()
638636
{
639-
$session = $this->getInstance(['sessionExpiration' => 0]);
637+
$session = $this->getInstance(['expiration' => 0]);
640638
$session->start();
641639

642640
$cookies = $session->cookies;

0 commit comments

Comments
 (0)