Skip to content

Commit 2f60e88

Browse files
committed
refactor: use properties
1 parent 778c412 commit 2f60e88

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Session\Handlers\Database;
1313

14+
use CodeIgniter\Session\Handlers\DatabaseHandler;
1415
use CodeIgniter\Test\CIUnitTestCase;
1516
use CodeIgniter\Test\DatabaseTestTrait;
1617
use CodeIgniter\Test\ReflectionHelper;
@@ -25,8 +26,12 @@ abstract class AbstractHandlerTestCase extends CIUnitTestCase
2526
use DatabaseTestTrait;
2627
use ReflectionHelper;
2728

28-
protected $refresh = true;
29-
protected $seed = CITestSeeder::class;
29+
protected $refresh = true;
30+
protected $seed = CITestSeeder::class;
31+
protected string $sessionDriver = DatabaseHandler::class;
32+
protected string $sessionSavePath = 'ci_sessions';
33+
protected string $sessionName = 'ci_session';
34+
protected string $userIpAddress = '127.0.0.1';
3035

3136
protected function setUp(): void
3237
{

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace CodeIgniter\Session\Handlers\Database;
1313

1414
use CodeIgniter\Config\Factories;
15-
use CodeIgniter\Session\Handlers\DatabaseHandler;
1615
use Config\App as AppConfig;
1716
use Config\Database as DatabaseConfig;
1817
use Config\Session as SessionConfig;
@@ -36,10 +35,10 @@ protected function setUp(): void
3635
protected function getInstance($options = [])
3736
{
3837
$defaults = [
39-
'driver' => DatabaseHandler::class,
40-
'cookieName' => 'ci_session',
38+
'driver' => $this->sessionDriver,
39+
'cookieName' => $this->sessionName,
4140
'expiration' => 7200,
42-
'savePath' => 'ci_sessions',
41+
'savePath' => $this->sessionSavePath,
4342
'matchIP' => false,
4443
'timeToUpdate' => 300,
4544
'regenerateDestroy' => false,
@@ -52,6 +51,6 @@ protected function getInstance($options = [])
5251
}
5352
Factories::injectMock('config', 'Session', $sessionConfig);
5453

55-
return new MySQLiHandler(new AppConfig(), '127.0.0.1');
54+
return new MySQLiHandler(new AppConfig(), $this->userIpAddress);
5655
}
5756
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace CodeIgniter\Session\Handlers\Database;
1313

1414
use CodeIgniter\Config\Factories;
15-
use CodeIgniter\Session\Handlers\DatabaseHandler;
1615
use Config\App as AppConfig;
1716
use Config\Database as DatabaseConfig;
1817
use Config\Session as SessionConfig;
@@ -36,10 +35,10 @@ protected function setUp(): void
3635
protected function getInstance($options = [])
3736
{
3837
$defaults = [
39-
'driver' => DatabaseHandler::class,
40-
'cookieName' => 'ci_session',
38+
'driver' => $this->sessionDriver,
39+
'cookieName' => $this->sessionName,
4140
'expiration' => 7200,
42-
'savePath' => 'ci_sessions',
41+
'savePath' => $this->sessionSavePath,
4342
'matchIP' => false,
4443
'timeToUpdate' => 300,
4544
'regenerateDestroy' => false,
@@ -52,6 +51,6 @@ protected function getInstance($options = [])
5251
}
5352
Factories::injectMock('config', 'Session', $sessionConfig);
5453

55-
return new PostgreHandler(new AppConfig(), '127.0.0.1');
54+
return new PostgreHandler(new AppConfig(), $this->userIpAddress);
5655
}
5756
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
*/
2828
final class RedisHandlerTest extends CIUnitTestCase
2929
{
30+
private string $sessionDriver = RedisHandler::class;
3031
private string $sessionName = 'ci_session';
3132
private string $sessionSavePath = 'tcp://127.0.0.1:6379';
3233
private string $userIpAddress = '127.0.0.1';
3334

3435
protected function getInstance($options = [])
3536
{
3637
$defaults = [
37-
'driver' => RedisHandler::class,
38+
'driver' => $this->sessionDriver,
3839
'cookieName' => $this->sessionName,
3940
'expiration' => 7200,
4041
'savePath' => $this->sessionSavePath,

0 commit comments

Comments
 (0)