Skip to content

Commit

Permalink
test: update failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Dec 17, 2022
1 parent 97eb3a7 commit 778c412
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 76 deletions.
33 changes: 15 additions & 18 deletions tests/system/Session/Handlers/Database/MySQLiHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace CodeIgniter\Session\Handlers\Database;

use CodeIgniter\Config\Factories;
use CodeIgniter\Session\Handlers\DatabaseHandler;
use Config\App as AppConfig;
use Config\Database as DatabaseConfig;
use Config\Session as SessionConfig;

/**
* @group DatabaseLive
Expand All @@ -34,27 +36,22 @@ protected function setUp(): void
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => DatabaseHandler::class,
'sessionCookieName' => 'ci_session',
'sessionExpiration' => 7200,
'sessionSavePath' => 'ci_sessions',
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
'driver' => DatabaseHandler::class,
'cookieName' => 'ci_session',
'expiration' => 7200,
'savePath' => 'ci_sessions',
'matchIP' => false,
'timeToUpdate' => 300,
'regenerateDestroy' => false,
];
$sessionConfig = new SessionConfig();
$config = array_merge($defaults, $options);

$config = array_merge($defaults, $options);
$appConfig = new AppConfig();

foreach ($config as $key => $c) {
$appConfig->{$key} = $c;
foreach ($config as $key => $value) {
$sessionConfig->{$key} = $value;
}
Factories::injectMock('config', 'Session', $sessionConfig);

return new MySQLiHandler($appConfig, '127.0.0.1');
return new MySQLiHandler(new AppConfig(), '127.0.0.1');
}
}
33 changes: 15 additions & 18 deletions tests/system/Session/Handlers/Database/PostgreHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace CodeIgniter\Session\Handlers\Database;

use CodeIgniter\Config\Factories;
use CodeIgniter\Session\Handlers\DatabaseHandler;
use Config\App as AppConfig;
use Config\Database as DatabaseConfig;
use Config\Session as SessionConfig;

/**
* @group DatabaseLive
Expand All @@ -34,27 +36,22 @@ protected function setUp(): void
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => DatabaseHandler::class,
'sessionCookieName' => 'ci_session',
'sessionExpiration' => 7200,
'sessionSavePath' => 'ci_sessions',
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
'driver' => DatabaseHandler::class,
'cookieName' => 'ci_session',
'expiration' => 7200,
'savePath' => 'ci_sessions',
'matchIP' => false,
'timeToUpdate' => 300,
'regenerateDestroy' => false,
];
$sessionConfig = new SessionConfig();
$config = array_merge($defaults, $options);

$config = array_merge($defaults, $options);
$appConfig = new AppConfig();

foreach ($config as $key => $c) {
$appConfig->{$key} = $c;
foreach ($config as $key => $value) {
$sessionConfig->{$key} = $value;
}
Factories::injectMock('config', 'Session', $sessionConfig);

return new PostgreHandler($appConfig, '127.0.0.1');
return new PostgreHandler(new AppConfig(), '127.0.0.1');
}
}
39 changes: 18 additions & 21 deletions tests/system/Session/Handlers/Database/RedisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace CodeIgniter\Session\Handlers\Database;

use CodeIgniter\Config\Factories;
use CodeIgniter\Session\Handlers\RedisHandler;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App as AppConfig;
use Config\Session as SessionConfig;
use Redis;

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

private function getInstance($options = [])
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => RedisHandler::class,
'sessionCookieName' => $this->sessionName,
'sessionExpiration' => 7200,
'sessionSavePath' => $this->sessionSavePath,
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
'driver' => RedisHandler::class,
'cookieName' => $this->sessionName,
'expiration' => 7200,
'savePath' => $this->sessionSavePath,
'matchIP' => false,
'timeToUpdate' => 300,
'regenerateDestroy' => false,
];
$sessionConfig = new SessionConfig();
$config = array_merge($defaults, $options);

$config = array_merge($defaults, $options);
$appConfig = new AppConfig();

foreach ($config as $key => $c) {
$appConfig->{$key} = $c;
foreach ($config as $key => $value) {
$sessionConfig->{$key} = $value;
}
Factories::injectMock('config', 'Session', $sessionConfig);

return new RedisHandler($appConfig, $this->userIpAddress);
return new RedisHandler(new AppConfig(), $this->userIpAddress);
}

public function testSavePathTimeoutFloat()
{
$handler = $this->getInstance(
['sessionSavePath' => 'tcp://127.0.0.1:6379?timeout=2.5']
['savePath' => 'tcp://127.0.0.1:6379?timeout=2.5']
);

$savePath = $this->getPrivateProperty($handler, 'savePath');
Expand All @@ -70,7 +67,7 @@ public function testSavePathTimeoutFloat()
public function testSavePathTimeoutInt()
{
$handler = $this->getInstance(
['sessionSavePath' => 'tcp://127.0.0.1:6379?timeout=10']
['savePath' => 'tcp://127.0.0.1:6379?timeout=10']
);

$savePath = $this->getPrivateProperty($handler, 'savePath');
Expand Down
36 changes: 17 additions & 19 deletions tests/system/Session/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Config\App as AppConfig;
use Config\Cookie as CookieConfig;
use Config\Logger as LoggerConfig;
use Config\Session as SessionConfig;

/**
* @runTestsInSeparateProcesses
Expand All @@ -42,27 +43,24 @@ protected function setUp(): void

protected function getInstance($options = [])
{
$appConfig = new AppConfig();

$defaults = [
'sessionDriver' => FileHandler::class,
'sessionCookieName' => 'ci_session',
'sessionExpiration' => 7200,
'sessionSavePath' => '',
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
'driver' => FileHandler::class,
'cookieName' => 'ci_session',
'expiration' => 7200,
'savePath' => '',
'matchIP' => false,
'timeToUpdate' => 300,
'regenerateDestroy' => false,
];
$sessionConfig = new SessionConfig();
$config = array_merge($defaults, $options);

$config = array_merge($defaults, $options);
$appConfig = new AppConfig();

foreach ($config as $key => $c) {
$appConfig->{$key} = $c;
foreach ($config as $key => $value) {
$sessionConfig->{$key} = $value;
}
Factories::injectMock('config', 'Session', $sessionConfig);

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

public function testExpires()
{
$session = $this->getInstance(['sessionExpiration' => 8000]);
$session = $this->getInstance(['expiration' => 8000]);
$session->start();

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

public function testExpiresOnClose()
{
$session = $this->getInstance(['sessionExpiration' => 0]);
$session = $this->getInstance(['expiration' => 0]);
$session->start();

$cookies = $session->cookies;
Expand Down

0 comments on commit 778c412

Please sign in to comment.