Added test cases for redis extension 5.3.7 and 6.0.0 (#6148)

This commit is contained in:
李铭昕 2023-09-14 16:55:00 +08:00 committed by GitHub
parent 1d6dd5b989
commit 46cf124d46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 12 deletions

View File

@ -319,3 +319,37 @@ jobs:
composer analyse src/model-cache
composer test src/model-cache
composer info | grep psr/simple-cache
ext-redis:
name: Test for Redis Module
runs-on: 'ubuntu-latest'
env:
PHP_VERSION: ${{ matrix.php-version }}
strategy:
matrix:
php-version: [ '8.1', '8.2' ]
redis: [ 'redis', 'redis-5.3.7' ]
max-parallel: 2
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpize
extensions: ${{ matrix.redis }}, swoole
ini-values: opcache.enable_cli=1
coverage: none
- name: Setup Swoole
run: ./.travis/swoole.install.sh
- name: Setup Packages
run: ./.travis/requirement.install.sh
- name: Setup Services
run: |
docker run --name redis -p 6379:6379 -d redis
sleep 20
- name: Run Test Cases
run: |
composer test src/redis

View File

@ -56,7 +56,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
tools: phpize
extensions: redis-5.3.7, pdo, pdo_mysql, bcmath
extensions: redis, pdo, pdo_mysql, bcmath
ini-values: opcache.enable_cli=0
coverage: none
- name: Setup Swoole

View File

@ -59,7 +59,7 @@ class ConfigFactoryTest extends TestCase
$this->assertSame('banana', $config->get('a.c.banana.name'));
$this->assertSame([
$this->assertEquals([
'id' => 'c',
'banana' => [
'name' => 'banana',

View File

@ -17,7 +17,7 @@
},
"require": {
"php": ">=8.1",
"ext-redis": "<6.0",
"ext-redis": "^5.0|^6.0",
"hyperf/contract": "~3.1.0",
"hyperf/pool": "~3.1.0",
"hyperf/support": "~3.1.0",

View File

@ -186,7 +186,7 @@ class RedisProxyTest extends TestCase
usleep(1000);
$redis->lRange('pipeline:list', 0, 1);
$redis->lTrim('pipeline:list', 2, -1);
usleep(10000);
usleep(20000);
$chan2->push($redis->exec());
});

View File

@ -66,7 +66,11 @@ class RedisTest extends TestCase
$this->assertSame('host', $host->getName());
$this->assertSame('port', $port->getName());
$this->assertSame('timeout', $timeout->getName());
$this->assertSame('retry_interval', $retryInterval->getName());
if (version_compare(phpversion('redis'), '6.0', '>=')) {
$this->assertSame('persistent_id', $retryInterval->getName());
} else {
$this->assertSame('retry_interval', $retryInterval->getName());
}
$this->assertTrue($redis->connect('127.0.0.1', 6379, 0.0, null, 0, 0));
}
@ -159,14 +163,31 @@ class RedisTest extends TestCase
$ref = new ReflectionClass(RedisCluster::class);
$method = $ref->getMethod('__construct');
$names = [
'name', 'seeds', 'timeout', 'read_timeout', 'persistent', 'auth',
['name', 'string'],
['seeds', 'array'],
['timeout', ['int', 'float']],
['read_timeout', ['int', 'float']],
['persistent', 'bool'],
['auth', 'mixed'],
['context', 'array'],
];
foreach ($method->getParameters() as $parameter) {
$this->assertSame(array_shift($names), $parameter->getName());
[$name, $type] = array_shift($names);
$this->assertSame($name, $parameter->getName());
if ($parameter->getName() === 'seeds') {
$this->assertSame('array', $parameter->getType()->getName());
} else {
$this->assertNull($parameter->getType());
if (version_compare(phpversion('redis'), '6.0', '>=')) {
if (is_array($type)) {
foreach ($parameter->getType()->getTypes() as $namedType) {
$this->assertTrue(in_array($namedType->getName(), $type));
}
} else {
$this->assertSame($type, $parameter->getType()->getName());
}
} else {
$this->assertNull($parameter->getType());
}
}
}
}
@ -202,11 +223,16 @@ class RedisTest extends TestCase
$rel = new ReflectionClass(RedisSentinel::class);
$method = $rel->getMethod('__construct');
$count = count($method->getParameters());
if ($count === 6) {
$this->markTestIncomplete('RedisSentinel don\'t support auth.');
}
$this->assertSame(7, $count);
if (version_compare(phpversion('redis'), '6.0', '>=')) {
$this->assertSame(1, $count);
$this->assertSame('options', $method->getParameters()[0]->getName());
} else {
if ($count === 6) {
$this->markTestIncomplete('RedisSentinel don\'t support auth.');
}
$this->assertSame(7, $count);
}
}
private function getRedis()