8000 Add tests for `serverName()` and `serverVersion()` · phpredis/phpredis@fa3eb00 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa3eb00

Browse files
Add tests for serverName() and serverVersion()
1 parent cbaf095 commit fa3eb00

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/RedisClusterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Redis_Cluster_Test extends Redis_Test {
2727
private static array $seed_messages = [];
2828
private static string $seed_source = '';
2929

30+
public function testServerInfo() { $this->markTestSkipped(); }
31+
public function testServerInfoOldRedis() { $this->markTestSkipped(); }
3032

3133
/* Tests we'll skip all together in the context of RedisCluster. The
3234
* RedisCluster class doesn't implement specialized (non-redis) commands

tests/RedisTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,55 @@ public function testInfo() {
24572457
$this->assertTrue(is_array($res) && isset($res['redis_version']) && isset($res['used_memory']));
24582458
}
24592459

2460+
private function execHello() {
2461+
$zipped = [];
2462+
2463+
$result = $this->redis->rawCommand('HELLO');
2464+
if ( ! is_array($result) || count($result) % 2 != 0)
2465+
return false;
2466+
2467+
for ($i = 0; $i < count($result); $i += 2) {
2468+
$zipped[$result[$i]] = $result[$i + 1];
2469+
}
2470+
2471+
return $zipped;
2472+
}
2473+
2474+
public function testServerInfo() {
2475+
if ( ! $this->minVersionCheck('6.0.0'))
2476+
$this->markTestSkipped();
2477+
2478+
$hello = $this->execHello();
2479+
if ( ! $this->assertArrayKey($hello, 'server') ||
2480+
! $this->assertArrayKey($hello, 'version'))
2481+
{
2482+
return false;
2483+
}
2484+
2485+
$this->assertEquals($hello['server'], $this->redis->serverName());
2486+
$this->assertEquals($hello['version'], $this->redis->serverVersion());
2487+
2488+
$info = $this->redis->info();
2489+
$cmd1 = $info['total_commands_processed'];
2490+
2491+
/* Shouldn't hit the server */
2492+
$this->assertEquals($hello['server'], $this->redis->serverName());
2493+
$this->assertEquals($hello['version'], $this->redis->serverVersion());
2494+
2495+
$info = $this->redis->info();
2496+
$cmd2 = $info['total_commands_processed'];
2497+
2498+
$this->assertEquals(1 + $cmd1, $cmd2);
2499+
}
2500+
2501+
public function testServerInfoOldRedis() {
2502+
if ($this->minVersionCheck('6.0.0'))
2503+
$this->markTestSkipped();
2504+
2505+
$this->assertFalse($this->redis->serverName());
2506+
$this->assertFalse($this->redis->serverVersion());
2507+
}
2508+
24602509
public function testInfoCommandStats() {
24612510
// INFO COMMANDSTATS is new in 2.6.0
24622511
if (version_compare($this->version, '2.5.0') < 0)

0 commit comments

Comments
 (0)
0