@@ -32,11 +32,6 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
32
32
*/
33
33
protected $ redisClient ;
34
34
35
- /**
36
- * @var \Redis
37
- */
38
- protected $ validator ;
39
-
40
35
/**
41
36
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
42
37
*/
@@ -52,9 +47,6 @@ protected function setUp()
52
47
53
48
$ host = getenv ('REDIS_HOST ' ) ?: 'localhost ' ;
54
49
55
- $ this ->validator = new \Redis ();
56
- $ this ->validator ->connect ($ host );
57
-
58
50
$ this ->redisClient = $ this ->createRedisClient ($ host );
59
51
$ this ->storage = new RedisSessionHandler (
60
52
$ this ->redisClient ,
@@ -82,8 +74,8 @@ public function testCloseSession()
82
74
83
75
public function testReadSession ()
84
76
{
85
- $ this ->setFixture (self ::PREFIX .'id1 ' , null );
86
- $ this ->setFixture (self ::PREFIX .'id2 ' , 'abc123 ' );
77
+ $ this ->redisClient -> set (self ::PREFIX .'id1 ' , null );
78
+ $ this ->redisClient -> set (self ::PREFIX .'id2 ' , 'abc123 ' );
87
79
88
80
$ this ->assertEquals ('' , $ this ->storage ->read ('id1 ' ));
89
81
$ this ->assertEquals ('abc123 ' , $ this ->storage ->read ('id2 ' ));
@@ -93,26 +85,26 @@ public function testWriteSession()
93
85
{
94
86
$ this ->assertTrue ($ this ->storage ->write ('id ' , 'data ' ));
95
87
96
- $ this ->assertTrue ($ this ->hasFixture (self ::PREFIX .'id ' ));
97
- $ this ->assertEquals ('data ' , $ this ->getFixture (self ::PREFIX .'id ' ));
88
+ $ this ->assertTrue (( bool ) $ this ->redisClient -> exists (self ::PREFIX .'id ' ));
89
+ $ this ->assertEquals ('data ' , $ this ->redisClient -> get (self ::PREFIX .'id ' ));
98
90
}
99
91
100
92
public function testUseSessionGcMaxLifetimeAsTimeToLive ()
101
93
{
102
94
$ this ->storage ->write ('id ' , 'data ' );
103
- $ ttl = $ this ->fixtureTtl (self ::PREFIX .'id ' );
95
+ $ ttl = $ this ->redisClient -> ttl (self ::PREFIX .'id ' );
104
96
105
97
$ this ->assertLessThanOrEqual (ini_get ('session.gc_maxlifetime ' ), $ ttl );
106
98
$ this ->assertGreaterThanOrEqual (0 , $ ttl );
107
99
}
108
100
109
101
public function testDestroySession ()
110
102
{
111
- $ this ->setFixture (self ::PREFIX .'id ' , 'foo ' );
103
+ $ this ->redisClient -> set (self ::PREFIX .'id ' , 'foo ' );
112
104
113
- $ this ->assertTrue ($ this ->hasFixture (self ::PREFIX .'id ' ));
105
+ $ this ->assertTrue (( bool ) $ this ->redisClient -> exists (self ::PREFIX .'id ' ));
114
106
$ this ->assertTrue ($ this ->storage ->destroy ('id ' ));
115
- $ this ->assertFalse ($ this ->hasFixture (self ::PREFIX .'id ' ));
107
+ $ this ->assertFalse (( bool ) $ this ->redisClient -> exists (self ::PREFIX .'id ' ));
116
108
}
117
109
118
110
public function testGcSession ()
@@ -122,12 +114,12 @@ public function testGcSession()
122
114
123
115
public function testUpdateTimestamp ()
124
116
{
125
- $ lowTTL = 10 ;
117
+ $ lowTtl = 10 ;
126
118
127
- $ this ->setFixture (self ::PREFIX .'id ' , 'foo ' , $ lowTTL );
119
+ $ this ->redisClient -> setex (self ::PREFIX .'id ' , $ lowTtl , 'foo ' );
128
120
$ this ->storage ->updateTimestamp ('id ' , array ());
129
121
130
- $ this ->assertGreaterThan ($ lowTTL , $ this ->fixtureTtl (self ::PREFIX .'id ' ));
122
+ $ this ->assertGreaterThan ($ lowTtl , $ this ->redisClient -> ttl (self ::PREFIX .'id ' ));
131
123
}
132
124
133
125
/**
@@ -150,28 +142,4 @@ public function getOptionFixtures(): array
150
142
array (array ('prefix ' => 'sfs ' , 'foo ' => 'bar ' ), false ),
151
143
);
152
144
}
153
-
154
- protected function setFixture ($ key , $ value , $ ttl = null )
155
- {
156
- if (null !== $ ttl ) {
157
- $ this ->validator ->setex ($ key , $ ttl , $ value );
158
- } else {
159
- $ this ->validator ->set ($ key , $ value );
160
- }
161
- }
162
-
163
- protected function getFixture ($ key )
164
- {
165
- return $ this ->validator ->get ($ key );
166
- }
167
-
168
- protected function hasFixture ($ key ): bool
169
- {
170
- return $ this ->validator ->exists ($ key );
171
- }
172
-
173
- protected function fixtureTtl ($ key ): int
174
- {
175
- return $ this ->validator ->ttl ($ key );
176
- }
177
145
}
0 commit comments