@@ -49,7 +49,7 @@ class RedisTest extends TestCase
49
49
protected function setUp ()
50
50
{
51
51
$ this ->environmentMock = $ this ->getMockBuilder (Environment::class)
52
- ->setMethods (['getRelationships ' , 'getAdminUrl ' ])
52
+ ->setMethods (['getRelationships ' , 'getAdminUrl ' , ' getVariable ' ])
53
53
->disableOriginalConstructor ()
54
54
->getMock ();
55
55
$ this ->loggerMock = $ this ->getMockBuilder (LoggerInterface::class)
@@ -65,7 +65,12 @@ protected function setUp()
65
65
);
66
66
}
67
67
68
- public function testExecute ()
68
+ /**
69
+ * @param $envSessionLocking
70
+ * @param int $expectedDisableLocking
71
+ * @dataProvider executeDataProvider
72
+ */
73
+ public function testExecute ($ envSessionLocking , int $ expectedDisableLocking )
69
74
{
70
75
$ this ->loggerMock ->expects ($ this ->once ())
71
76
->method ('info ' )
@@ -83,7 +88,10 @@ public function testExecute()
83
88
$ this ->environmentMock ->expects ($ this ->any ())
84
89
->method ('getAdminUrl ' )
85
90
->willReturn ('admin ' );
86
-
91
+ $ this ->environmentMock ->expects ($ this ->once ())
92
+ ->method ('getVariable ' )
93
+ ->with (Environment::VAR_REDIS_SESSION_DISABLE_LOCKING )
94
+ ->willReturn ($ envSessionLocking );
87
95
$ this ->configReaderMock ->expects ($ this ->once ())
88
96
->method ('read ' )
89
97
->willReturn ([]);
@@ -117,13 +125,32 @@ public function testExecute()
117
125
'host ' => '127.0.0.1 ' ,
118
126
'port ' => '6379 ' ,
119
127
'database ' => 0 ,
128
+ 'disable_locking ' => $ expectedDisableLocking
120
129
],
121
130
],
122
131
]);
123
132
124
133
$ this ->process ->execute ();
125
134
}
126
135
136
+ public function executeDataProvider ()
137
+ {
138
+ return [
139
+ [
140
+ '' ,
141
+ 1
142
+ ],
143
+ [
144
+ Environment::VAL_DISABLED ,
145
+ 0
146
+ ],
147
+ [
148
+ Environment::VAL_ENABLED ,
149
+ 1
150
+ ]
151
+ ];
152
+ }
153
+
127
154
public function testExecuteRemovingRedis ()
128
155
{
129
156
$ this ->loggerMock ->expects ($ this ->once ())
@@ -182,4 +209,83 @@ public function testExecuteRemovingRedis()
182
209
183
210
$ this ->process ->execute ();
184
211
}
212
+
213
+
214
+ public function testExecuteWithDifferentRedisOptions ()
215
+ {
216
+ $ this ->loggerMock ->expects ($ this ->once ())
217
+ ->method ('info ' )
218
+ ->with ('Updating env.php Redis cache configuration. ' );
219
+ $ this ->environmentMock ->expects ($ this ->any ())
220
+ ->method ('getRelationships ' )
221
+ ->willReturn ([
222
+ 'redis ' => [
223
+ 0 => [
224
+ 'host ' => '127.0.0.1 ' ,
225
+ 'port ' => '6379 '
226
+ ]
227
+ ],
228
+ ]);
229
+ $ this ->environmentMock ->expects ($ this ->any ())
230
+ ->method ('getAdminUrl ' )
231
+ ->willReturn ('admin ' );
232
+ $ this ->environmentMock ->expects ($ this ->once ())
233
+ ->method ('getVariable ' )
234
+ ->with (Environment::VAR_REDIS_SESSION_DISABLE_LOCKING )
235
+ ->willReturn ('' );
236
+ $ this ->configReaderMock ->expects ($ this ->once ())
237
+ ->method ('read ' )
238
+ ->willReturn ([
239
+ 'session ' => [
240
+ 'redis ' => [
241
+ 'max_concurrency ' => 10 ,
242
+ 'bot_first_lifetime ' => 100 ,
243
+ 'bot_lifetime ' => 10000 ,
244
+ 'min_lifetime ' => 100 ,
245
+ 'max_lifetime ' => 10000
246
+ ]
247
+ ]
248
+ ]);
249
+
250
+ $ this ->configWriterMock ->expects ($ this ->once ())
251
+ ->method ('write ' )
252
+ ->with ([
253
+ 'cache ' => [
254
+ 'frontend ' => [
255
+ 'default ' => [
256
+ 'backend ' => 'Cm_Cache_Backend_Redis ' ,
257
+ 'backend_options ' => [
258
+ 'server ' => '127.0.0.1 ' ,
259
+ 'port ' => '6379 ' ,
260
+ 'database ' => 1 ,
261
+ ],
262
+ ],
263
+ 'page_cache ' => [
264
+ 'backend ' => 'Cm_Cache_Backend_Redis ' ,
265
+ 'backend_options ' => [
266
+ 'server ' => '127.0.0.1 ' ,
267
+ 'port ' => '6379 ' ,
268
+ 'database ' => 1 ,
269
+ ],
270
+ ],
271
+ ],
272
+ ],
273
+ 'session ' => [
274
+ 'save ' => 'redis ' ,
275
+ 'redis ' => [
276
+ 'host ' => '127.0.0.1 ' ,
277
+ 'port ' => '6379 ' ,
278
+ 'database ' => 0 ,
279
+ 'disable_locking ' => 1 ,
280
+ 'max_concurrency ' => 10 ,
281
+ 'bot_first_lifetime ' => 100 ,
282
+ 'bot_lifetime ' => 10000 ,
283
+ 'min_lifetime ' => 100 ,
284
+ 'max_lifetime ' => 10000
285
+ ],
286
+ ],
287
+ ]);
288
+
289
+ $ this ->process ->execute ();
290
+ }
185
291
}
0 commit comments