Skip to content

Commit 5b42d35

Browse files
authored
Added test cases for redis extension 5.3.7 and 6.0.0 (#6148)
1 parent 728e350 commit 5b42d35

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"require": {
1919
"php": ">=8.1",
20-
"ext-redis": "<6.0",
20+
"ext-redis": "^5.0|^6.0",
2121
"hyperf/contract": "~3.1.0",
2222
"hyperf/pool": "~3.1.0",
2323
"hyperf/support": "~3.1.0",

tests/RedisProxyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function testRedisPipeline()
186186
usleep(1000);
187187
$redis->lRange('pipeline:list', 0, 1);
188188
$redis->lTrim('pipeline:list', 2, -1);
189-
usleep(10000);
189+
usleep(20000);
190190
$chan2->push($redis->exec());
191191
});
192192

tests/RedisTest.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public function testRedisConnect()
6666
$this->assertSame('host', $host->getName());
6767
$this->assertSame('port', $port->getName());
6868
$this->assertSame('timeout', $timeout->getName());
69-
$this->assertSame('retry_interval', $retryInterval->getName());
69+
if (version_compare(phpversion('redis'), '6.0', '>=')) {
70+
$this->assertSame('persistent_id', $retryInterval->getName());
71+
} else {
72+
$this->assertSame('retry_interval', $retryInterval->getName());
73+
}
7074

7175
$this->assertTrue($redis->connect('127.0.0.1', 6379, 0.0, null, 0, 0));
7276
}
@@ -159,14 +163,31 @@ public function testRedisClusterConstructor()
159163
$ref = new ReflectionClass(RedisCluster::class);
160164
$method = $ref->getMethod('__construct');
161165
$names = [
162-
'name', 'seeds', 'timeout', 'read_timeout', 'persistent', 'auth',
166+
['name', 'string'],
167+
['seeds', 'array'],
168+
['timeout', ['int', 'float']],
169+
['read_timeout', ['int', 'float']],
170+
['persistent', 'bool'],
171+
['auth', 'mixed'],
172+
['context', 'array'],
163173
];
164174
foreach ($method->getParameters() as $parameter) {
165-
$this->assertSame(array_shift($names), $parameter->getName());
175+
[$name, $type] = array_shift($names);
176+
$this->assertSame($name, $parameter->getName());
166177
if ($parameter->getName() === 'seeds') {
167178
$this->assertSame('array', $parameter->getType()->getName());
168179
} else {
169-
$this->assertNull($parameter->getType());
180+
if (version_compare(phpversion('redis'), '6.0', '>=')) {
181+
if (is_array($type)) {
182+
foreach ($parameter->getType()->getTypes() as $namedType) {
183+
$this->assertTrue(in_array($namedType->getName(), $type));
184+
}
185+
} else {
186+
$this->assertSame($type, $parameter->getType()->getName());
187+
}
188+
} else {
189+
$this->assertNull($parameter->getType());
190+
}
170191
}
171192
}
172193
}
@@ -202,11 +223,16 @@ public function testRedisSentinelParams()
202223
$rel = new ReflectionClass(RedisSentinel::class);
203224
$method = $rel->getMethod('__construct');
204225
$count = count($method->getParameters());
205-
if ($count === 6) {
206-
$this->markTestIncomplete('RedisSentinel don\'t support auth.');
207-
}
208226

209-
$this->assertSame(7, $count);
227+
if (version_compare(phpversion('redis'), '6.0', '>=')) {
228+
$this->assertSame(1, $count);
229+
$this->assertSame('options', $method->getParameters()[0]->getName());
230+
} else {
231+
if ($count === 6) {
232+
$this->markTestIncomplete('RedisSentinel don\'t support auth.');
233+
}
234+
$this->assertSame(7, $count);
235+
}
210236
}
211237

212238
private function getRedis()

0 commit comments

Comments
 (0)