Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6cd665

Browse files
Code formatting
1 parent 78b70ca commit c6cd665

6 files changed

Lines changed: 144 additions & 148 deletions

File tree

tests/RedisArrayTest.php

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
function custom_hash($str) {
88
// str has the following format: $APPID_fb$FACEBOOKID_$key.
99
$pos = strpos($str, '_fb');
10-
if(preg_match("#\w+_fb(?<facebook_id>\d+)_\w+#", $str, $out)) {
10+
if (preg_match("#\w+_fb(?<facebook_id>\d+)_\w+#", $str, $out)) {
1111
return $out['facebook_id'];
1212
}
1313
return $str;
@@ -21,7 +21,7 @@ function parseHostPort($str, &$host, &$port) {
2121

2222
function getRedisVersion(object $client) {
2323
$arr_info = $client->info();
24-
if (!$arr_info || !isset($arr_info['redis_version'])) {
24+
if ( ! $arr_info || !isset($arr_info['redis_version'])) {
2525
return '0.0.0';
2626
}
2727
return $arr_info['redis_version'];
@@ -51,7 +51,7 @@ public function setUp() {
5151
// initialize strings.
5252
$n = REDIS_ARRAY_DATA_SIZE;
5353
$this->strings = [];
54-
for($i = 0; $i < $n; $i++) {
54+
for ($i = 0; $i < $n; $i++) {
5555
$this->strings['key-'.$i] = 'val-'.$i;
5656
}
5757

@@ -70,12 +70,12 @@ public function testMSet() {
7070
$this->assertTrue($this->ra->mset($this->strings));
7171

7272
// check each key individually using the array
73-
foreach($this->strings as $k => $v) {
73+
foreach ($this->strings as $k => $v) {
7474
$this->assertEquals($v, $this->ra->get($k));
7575
}
7676

7777
// check each key individually using a new connection
78-
foreach($this->strings as $k => $v) {
78+
foreach ($this->strings as $k => $v) {
7979
parseHostPort($this->ra->_target($k), $host, $port);
8080

8181
$target = $this->ra->_target($k);
@@ -99,7 +99,7 @@ public function testMGet() {
9999

100100
private function addData($commonString) {
101101
$this->data = [];
102-
for($i = 0; $i < REDIS_ARRAY_DATA_SIZE; $i++) {
102+
for ($i = 0; $i < REDIS_ARRAY_DATA_SIZE; $i++) {
103103
$k = rand().'_'.$commonString.'_'.rand();
104104
$this->data[$k] = rand();
105105
}
@@ -109,9 +109,9 @@ private function addData($commonString) {
109109
private function checkCommonLocality() {
110110
// check that they're all on the same node.
111111
$lastNode = NULL;
112-
foreach($this->data as $k => $v) {
112+
foreach ($this->data as $k => $v) {
113113
$node = $this->ra->_target($k);
114-
if($lastNode) {
114+
if ($lastNode) {
115115
$this->assertEquals($node, $lastNode);
116116
}
117117
$this->assertEqualsWeak($v, $this->ra->get($k));
@@ -172,7 +172,7 @@ public function testKeyDistributor()
172172

173173
// check that they're all on the expected node.
174174
$lastNode = NULL;
175-
foreach($this->data as $k => $v) {
175+
foreach ($this->data as $k => $v) {
176176
$node = $this->ra->_target($k);
177177
$pos = $this->customDistributor($k);
178178
$this->assertEquals($node, $new_ring[$pos]);
@@ -238,30 +238,30 @@ public function setUp() {
238238
// initialize strings.
239239
$n = REDIS_ARRAY_DATA_SIZE;
240240
$this->strings = [];
241-
for($i = 0; $i < $n; $i++) {
241+
for ($i = 0; $i < $n; $i++) {
242242
$this->strings['key-'.$i] = 'val-'.$i;
243243
}
244244

245245
// initialize sets
246-
for($i = 0; $i < $n; $i++) {
246+
for ($i = 0; $i < $n; $i++) {
247247
// each set has 20 elements
248248
$this->sets['set-'.$i] = range($i, $i+20);
249249
}
250250

251251
// initialize lists
252-
for($i = 0; $i < $n; $i++) {
252+
for ($i = 0; $i < $n; $i++) {
253253
// each list has 20 elements
254254
$this->lists['list-'.$i] = range($i, $i+20);
255255
}
256256

257257
// initialize hashes
258-
for($i = 0; $i < $n; $i++) {
258+
for ($i = 0; $i < $n; $i++) {
259259
// each hash has 5 keys
260260
$this->hashes['hash-'.$i] = ['A' => $i, 'B' => $i+1, 'C' => $i+2, 'D' => $i+3, 'E' => $i+4];
261261
}
262262

263263
// initialize sorted sets
264-
for($i = 0; $i < $n; $i++) {
264+
for ($i = 0; $i < $n; $i++) {
265265
// each sorted sets has 5 elements
266266
$this->zsets['zset-'.$i] = [$i, 'A', $i+1, 'B', $i+2, 'C', $i+3, 'D', $i+4, 'E'];
267267
}
@@ -282,7 +282,7 @@ public function setUp() {
282282
public function testFlush() {
283283
// flush all servers first.
284284
global $server_list;
285-
foreach($server_list as $s) {
285+
foreach ($server_list as $s) {
286286
parseHostPort($s, $host, $port);
287287

288288
$r = new Redis();
@@ -298,27 +298,27 @@ public function testFlush() {
298298
private function distributeKeys() {
299299

300300
// strings
301-
foreach($this->strings as $k => $v) {
301+
foreach ($this->strings as $k => $v) {
302302
$this->ra->set($k, $v);
303303
}
304304

305305
// sets
306-
foreach($this->sets as $k => $v) {
306+
foreach ($this->sets as $k => $v) {
307307
call_user_func_array([$this->ra, 'sadd'], array_merge([$k], $v));
308308
}
309309

310310
// lists
311-
foreach($this->lists as $k => $v) {
311+
foreach ($this->lists as $k => $v) {
312312
call_user_func_array([$this->ra, 'rpush'], array_merge([$k], $v));
313313
}
314314

315315
// hashes
316-
foreach($this->hashes as $k => $v) {
316+
foreach ($this->hashes as $k => $v) {
317317
$this->ra->hmset($k, $v);
318318
}
319319

320320
// sorted sets
321-
foreach($this->zsets as $k => $v) {
321+
foreach ($this->zsets as $k => $v) {
322322
call_user_func_array([$this->ra, 'zadd'], array_merge([$k], $v));
323323
}
324324
}
@@ -334,36 +334,36 @@ public function testSimpleRead() {
334334
private function readAllvalues() {
335335

336336
// strings
337-
foreach($this->strings as $k => $v) {
337+
foreach ($this->strings as $k => $v) {
338338
$this->assertEquals($v, $this->ra->get($k));
339339
}
340340

341341
// sets
342-
foreach($this->sets as $k => $v) {
342+
foreach ($this->sets as $k => $v) {
343343
$ret = $this->ra->smembers($k); // get values
344344

345345
$this->assertEqualsWeak($v, $ret);
346346
}
347347

348348
// lists
349-
foreach($this->lists as $k => $v) {
349+
foreach ($this->lists as $k => $v) {
350350
$ret = $this->ra->lrange($k, 0, -1);
351351
$this->assertEqualsWeak($v, $ret);
352352
}
353353

354354
// hashes
355-
foreach($this->hashes as $k => $v) {
355+
foreach ($this->hashes as $k => $v) {
356356
$ret = $this->ra->hgetall($k); // get values
357357
$this->assertEqualsWeak($v, $ret);
358358
}
359359

360360
// sorted sets
361-
foreach($this->zsets as $k => $v) {
362-
$ret = $this->ra->zrange($k, 0, -1, TRUE);
361+
foreach ($this->zsets as $k => $v) {
362+
$ret = $this->ra->zrange($k, 0, -1, true);
363363

364364
// create assoc array from local dataset
365365
$tmp = [];
366-
for($i = 0; $i < count($v); $i += 2) {
366+
for ($i = 0; $i < count($v); $i += 2) {
367367
$tmp[$v[$i+1]] = $v[$i];
368368
}
369369

@@ -413,15 +413,15 @@ public function setUp() {
413413
// initialize strings.
414414
$n = REDIS_ARRAY_DATA_SIZE;
415415
$this->strings = [];
416-
for($i = 0; $i < $n; $i++) {
416+
for ($i = 0; $i < $n; $i++) {
417417
$this->strings['key-'.$i] = 'val-'.$i;
418418
}
419419

420420
global $new_ring, $old_ring, $useIndex;
421421
$options = [
422422
'previous' => $old_ring,
423423
'index' => $useIndex,
424-
'autorehash' => TRUE
424+
'autorehash' => true
425425
];
426426
if ($this->getAuth()) {
427427
$options['auth'] = $this->getAuth();
@@ -433,13 +433,13 @@ public function setUp() {
433433

434434
public function testDistribute() {
435435
// strings
436-
foreach($this->strings as $k => $v) {
436+
foreach ($this->strings as $k => $v) {
437437
$this->ra->set($k, $v);
438438
}
439439
}
440440

441441
private function readAllvalues() {
442-
foreach($this->strings as $k => $v) {
442+
foreach ($this->strings as $k => $v) {
443443
$this->assertEquals($v, $this->ra->get($k));
444444
}
445445
}
@@ -463,7 +463,7 @@ public function testReadAndMigrateAll() {
463463

464464
// Read and migrate keys on fallback, causing the whole ring to be rehashed.
465465
public function testAllKeysHaveBeenMigrated() {
466-
foreach($this->strings as $k => $v) {
466+
foreach ($this->strings as $k => $v) {
467467
parseHostPort($this->ra->_target($k), $host, $port);
468468

469469
$r = new Redis;
@@ -510,9 +510,9 @@ public function testInit() {
510510
public function testKeyDistribution() {
511511
// check that all of joe's keys are on the same instance
512512
$lastNode = NULL;
513-
foreach(['name', 'group', 'salary'] as $field) {
513+
foreach (['name', 'group', 'salary'] as $field) {
514514
$node = $this->ra->_target('1_{employee:joe}_'.$field);
515-
if($lastNode) {
515+
if ($lastNode) {
516516
$this->assertEquals($node, $lastNode);
517517
}
518518
$lastNode = $node;
@@ -554,7 +554,6 @@ public function testMultiExecMSet() {
554554
}
555555

556556
public function testMultiExecMGet() {
557-
// test MGET
558557
$out = $this->ra->multi($this->ra->_target('{employee:joe}'))
559558
->mget(['1_{employee:joe}_group', '1_{employee:joe}_salary'])
560559
->exec();
@@ -564,8 +563,6 @@ public function testMultiExecMGet() {
564563
}
565564

566565
public function testMultiExecDel() {
567-
568-
// test DEL
569566
$out = $this->ra->multi($this->ra->_target('{employee:joe}'))
570567
->del('1_{employee:joe}_group', '1_{employee:joe}_salary')
571568
->exec();

tests/RedisClusterTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ public function testPubSub() {
345345
$this->assertIsArray($result);
346346
$this->assertEquals(4, count($result));
347347

348-
$arr_zipped = [];
349-
for ($i = 0; $i <= count($result) / 2; $i+=2) {
350-
$arr_zipped[$result[$i]] = $result[$i+1];
348+
$zipped = [];
349+
for ($i = 0; $i <= count($result) / 2; $i += 2) {
350+
$zipped[$result[$i]] = $result[$i+1];
351351
}
352-
$result = $arr_zipped;
352+
$result = $zipped;
353353

354354
// Make sure the elements are correct, and have zero counts
355355
foreach([$c1,$c2] as $channel) {
@@ -640,6 +640,7 @@ protected function setKeyVals($key_index, $key_type, &$arr_ref) {
640640

641641
/* Update our reference array so we can verify values */
642642
$arr_ref[$key] = $value;
643+
643644
return $key;
644645
}
645646

@@ -757,7 +758,7 @@ public function testSession()
757758
@ini_set('session.save_handler', 'rediscluster');
758759
@ini_set('session.save_path', $this->sessionSavePath() . '&failover=error');
759760

760-
if (!@session_start())
761+
if ( ! @session_start())
761762
$this->markTestSkipped();
762763

763764
session_write_close();

0 commit comments

Comments
 (0)