1111
1212namespace CodeIgniter \Session \Handlers \Database ;
1313
14+ use CodeIgniter \Config \Factories ;
1415use CodeIgniter \Session \Handlers \RedisHandler ;
1516use CodeIgniter \Test \CIUnitTestCase ;
1617use Config \App as AppConfig ;
18+ use Config \Session as SessionConfig ;
1719use 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 ' );
0 commit comments