Skip to content

Commit 86b8f7f

Browse files
committed
added validation to exception message
1 parent 0170df4 commit 86b8f7f

File tree

2 files changed

+43
-50
lines changed

2 files changed

+43
-50
lines changed

src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function selectKeyHashTag($options)
108108
return $this->getDefaultKeyHashTag($options); // defaulting to keyHashTag or {SPLITIO}
109109
}
110110
$keyHashTags = $options['keyHashTags'];
111-
$msg = $this->isValidConfigArray($keyHashTags, 'keyHashTags'); // check if is valid array
111+
$msg = $this->isValidConfigArray($keyHashTags, 'keyHashTag'); // check if is valid array
112112
if (!is_null($msg)) {
113113
throw new AdapterException($msg);
114114
}

tests/Suite/Adapter/RedisAdapterTest.php

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ private function getMockedLogger()
2424

2525
public function testRedisWithNullValues()
2626
{
27-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', "Wrong configuration of redis.");
27+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
28+
$this->expectExceptionMessage("Wrong configuration of redis.");
2829

2930
$predis = new PRedis(array());
3031
}
@@ -107,7 +108,8 @@ public function testRedisWithParametersPrefixAndSentinels()
107108

108109
public function testRedisWithEmptySentinels()
109110
{
110-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', 'At least one sentinel is required.');
111+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
112+
$this->expectExceptionMessage('At least one sentinel is required.');
111113

112114
$predis = new PRedis(array(
113115
'sentinels' => array(),
@@ -119,7 +121,8 @@ public function testRedisWithEmptySentinels()
119121

120122
public function testRedisWithSentinelsWithoutOptions()
121123
{
122-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', "Wrong configuration of redis.");
124+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
125+
$this->expectExceptionMessage("Wrong configuration of redis.");
123126

124127
$predis = new PRedis(array(
125128
'sentinels' => array(
@@ -130,7 +133,9 @@ public function testRedisWithSentinelsWithoutOptions()
130133

131134
public function testRedisWithSentinelsWithoutReplicationOption()
132135
{
133-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', "Wrong configuration of redis.");
136+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', );
137+
$this->expectExceptionMessage("Wrong configuration of redis.");
138+
134139
$predis = new PRedis(array(
135140
'sentinels' => array(
136141
'127.0.0.1'
@@ -146,7 +151,8 @@ public function testRedisWithSentinelsWithWrongReplicationOption()
146151
->method('warning')
147152
->with($this->equalTo("'replication' option was deprecated please use 'distributedStrategy'"));
148153

149-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', "Wrong configuration of redis 'distributedStrategy'.");
154+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
155+
$this->expectExceptionMessage("Wrong configuration of redis 'distributedStrategy'.");
150156

151157
$predis = new PRedis(array(
152158
'sentinels' => array(
@@ -165,10 +171,8 @@ public function testRedisWithSentinelsWithoutServiceOption()
165171
->method('warning')
166172
->with($this->equalTo("'replication' option was deprecated please use 'distributedStrategy'"));
167173

168-
$this->expectException(
169-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
170-
'Master name is required in replication mode for sentinel.'
171-
);
174+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
175+
$this->expectExceptionMessage('Master name is required in replication mode for sentinel.');
172176

173177
$predis = new PRedis(array(
174178
'sentinels' => array(
@@ -184,7 +188,8 @@ public function testRedisWithWrongTypeOfSentinels()
184188
{
185189
$logger = $this->getMockedLogger();
186190

187-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', 'sentinels must be an array.');
191+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException',);
192+
$this->expectExceptionMessage('sentinels must be an array.');
188193

189194
$predis = new PRedis(array(
190195
'sentinels' => "test",
@@ -196,10 +201,8 @@ public function testRedisWithWrongTypeOfSentinels()
196201

197202
public function testRedisSentinelWithWrongRedisDistributedStrategy()
198203
{
199-
$this->expectException(
200-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
201-
"Wrong configuration of redis 'distributedStrategy'."
202-
);
204+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
205+
$this->expectExceptionMessage("Wrong configuration of redis 'distributedStrategy'.");
203206

204207
$predis = new PRedis(array(
205208
'sentinels' => array(
@@ -250,7 +253,8 @@ public function testRedisWithSentinelsAndDistributedStrategy()
250253

251254
public function testRedisWithEmptyClusters()
252255
{
253-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', 'At least one clusterNode is required.');
256+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
257+
$this->expectExceptionMessage('At least one clusterNode is required.');
254258

255259
$predis = new PRedis(array(
256260
'clusterNodes' => array(),
@@ -263,7 +267,8 @@ public function testRedisWithEmptyClusters()
263267

264268
public function testRedisWithClustersWithoutOptions()
265269
{
266-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', "Wrong configuration of redis.");
270+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
271+
$this->expectExceptionMessage("Wrong configuration of redis.");
267272

268273
$predis = new PRedis(array(
269274
'clusterNodes' => array(
@@ -274,7 +279,8 @@ public function testRedisWithClustersWithoutOptions()
274279

275280
public function testRedisWithWrongTypeOfClusters()
276281
{
277-
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException', 'clusterNodes must be an array.');
282+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
283+
$this->expectExceptionMessage('clusterNodes must be an array.');
278284

279285
$predis = new PRedis(array(
280286
'clusterNodes' => "test",
@@ -287,10 +293,8 @@ public function testRedisWithWrongTypeOfClusters()
287293

288294
public function testRedisClusterWithWrongRedisDistributedStrategy()
289295
{
290-
$this->expectException(
291-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
292-
"Wrong configuration of redis 'distributedStrategy'."
293-
);
296+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
297+
$this->expectExceptionMessage("Wrong configuration of redis 'distributedStrategy'.");
294298

295299
$predis = new PRedis(array(
296300
'clusterNodes' => array(
@@ -304,10 +308,8 @@ public function testRedisClusterWithWrongRedisDistributedStrategy()
304308

305309
public function testRedisWithInvalidKeyHashtagInClusters()
306310
{
307-
$this->expectException(
308-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
309-
"keyHashTag is not valid."
310-
);
311+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
312+
$this->expectExceptionMessage("keyHashTag is not valid.");
311313

312314
$predis = new PRedis(array(
313315
'clusterNodes' => array(
@@ -324,10 +326,8 @@ public function testRedisWithInvalidKeyHashtagInClusters()
324326

325327
public function testRedisWithInvalidBeginingKeyHashtagInClusters()
326328
{
327-
$this->expectException(
328-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
329-
"keyHashTag is not valid."
330-
);
329+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
330+
$this->expectExceptionMessage("keyHashTag is not valid.");
331331

332332
$predis = new PRedis(array(
333333
'clusterNodes' => array(
@@ -344,10 +344,8 @@ public function testRedisWithInvalidBeginingKeyHashtagInClusters()
344344

345345
public function testRedisWithWrongTypeKeyHashtagInClusters()
346346
{
347-
$this->expectException(
348-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
349-
"keyHashTag must be string."
350-
);
347+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
348+
$this->expectExceptionMessage("keyHashTag must be string.");
351349

352350
$predis = new PRedis(array(
353351
'clusterNodes' => array(
@@ -364,10 +362,8 @@ public function testRedisWithWrongTypeKeyHashtagInClusters()
364362

365363
public function testRedisWithWrongLengthKeyHashtagInClusters()
366364
{
367-
$this->expectException(
368-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
369-
"keyHashTag is not valid."
370-
);
365+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
366+
$this->expectExceptionMessage("keyHashTag is not valid.");
371367

372368
$predis = new PRedis(array(
373369
'clusterNodes' => array(
@@ -415,10 +411,9 @@ public function testRedisWithoutCustomKeyHashtagClusters()
415411

416412
public function testRedisWithClustersKeyHashTags()
417413
{
418-
$this->expectException(
419-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
420-
"keyHashTags must be array."
421-
);
414+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
415+
$this->expectExceptionMessage("keyHashTags must be an array.");
416+
422417
$predis = new PRedis(array(
423418
'clusterNodes' => array(
424419
'tcp://MYIP:26379?timeout=3'
@@ -434,10 +429,9 @@ public function testRedisWithClustersKeyHashTags()
434429

435430
public function testRedisWithClustersKeyHashTagsInvalid()
436431
{
437-
$this->expectException(
438-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
439-
"keyHashTags size is zero after filtering valid elements."
440-
);
432+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
433+
$this->expectExceptionMessage("keyHashTags size is zero after filtering valid elements.");
434+
441435
$predis = new PRedis(array(
442436
'clusterNodes' => array(
443437
'tcp://MYIP:26379?timeout=3'
@@ -453,10 +447,9 @@ public function testRedisWithClustersKeyHashTagsInvalid()
453447

454448
public function testRedisWithClustersKeyHashTagsInvalidHashTags()
455449
{
456-
$this->expectException(
457-
'SplitIO\Component\Cache\Storage\Exception\AdapterException',
458-
"keyHashTags size is zero after filtering valid elements."
459-
);
450+
$this->expectException('SplitIO\Component\Cache\Storage\Exception\AdapterException');
451+
$this->expectExceptionMessage("keyHashTags size is zero after filtering valid elements.");
452+
460453
$predis = new PRedis(array(
461454
'clusterNodes' => array(
462455
'tcp://MYIP:26379?timeout=3'

0 commit comments

Comments
 (0)