8000 fix Redis 6 proxy tests · symfony/symfony@9c1cfd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c1cfd6

Browse files
committed
fix Redis 6 proxy tests
1 parent c87e4a1 commit 9c1cfd6

File tree

5 files changed

+100
-42
lines changed

5 files changed

+100
-42
lines changed

src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,31 @@ public function testRelayProxy()
8686
*/
8787
public function testRedis6Proxy($class, $stub)
8888
{
89-
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
89+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
90+
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
91+
} else {
92+
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/6.0.2/{$stub}.stub.php");
93+
}
94+
9095
$stub = preg_replace('/^class /m', 'return; \0', $stub);
9196
$stub = preg_replace('/^return; class ([a-zA-Z]++)/m', 'interface \1StubInterface', $stub, 1);
9297
$stub = preg_replace('/^ public const .*/m', '', $stub);
9398
eval(substr($stub, 5));
94-
$r = new \ReflectionClass($class.'StubInterface');
9599

96-
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}6Proxy.php");
97-
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
100+
$this->assertEquals(self::dumpMethods(new \ReflectionClass($class.'StubInterface')), self::dumpMethods(new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\%s6Proxy', $class))));
101+
}
102+
103+
private static function dumpMethods(\ReflectionClass $class): string
104+
{
98105
$methods = [];
99106

100-
foreach ($r->getMethods() as $method) {
107+
foreach ($class->getMethods() as $method) {
101108
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
102109
continue;
103110
}
111+
104112
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
105113
$signature = ProxyHelper::exportSignature($method, false, $args);
106-
107-
if ('Redis' === $class && 'mget' === $method->name) {
108-
$signature = str_replace(': \Redis|array|false', ': \Redis|array', $signature);
109-
}
110-
111-
if ('RedisCluster' === $class && 'publish' === $method->name) {
112-
$signature = str_replace(': \RedisCluster|bool|int', ': \RedisCluster|bool', $signature);
113-
}
114-
115114
$methods[] = "\n ".str_replace('timeout = 0.0', 'timeout = 0', $signature)."\n".<<<EOPHP
116115
{
117116
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
@@ -120,9 +119,8 @@ public function testRedis6Proxy($class, $stub)
120119
EOPHP;
121120
}
122121

123-
uksort($methods, 'strnatcmp');
124-
$proxy .= implode('', $methods)."}\n";
122+
usort($methods, 'strnatcmp');
125123

126-
$this->assertStringEqualsFile(\dirname(__DIR__, 2)."/Traits/{$class}6Proxy.php", $proxy);
124+
return implode("\n", $methods);
127125
}
128126
}

src/Symfony/Component/Cache/Traits/Redis6Proxy.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
2828
use LazyProxyTrait {
2929
resetLazyObject as reset;
3030
}
31+
use Redis6ProxyTrait;
3132

3233
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
3334

@@ -96,11 +97,6 @@ public function bgrewriteaof(): \Redis|bool
9697
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgrewriteaof(...\func_get_args());
9798
}
9899

99-
public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
100-
{
101-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
102-
}
103-
104100
public function bitcount($key, $start = 0, $end = -1, $bybit = false): \Redis|false|int
105101
{
106102
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bitcount(...\func_get_args());
@@ -231,11 +227,6 @@ public function discard(): \Redis|bool
231227
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
232228
}
233229

234-
public function dump($key): \Redis|string
235-
{
236-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
237-
}
238-
239230
public function echo($str): \Redis|false|string
240231
{
241232
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
@@ -656,11 +647,6 @@ public function ltrim($key, $start, $end): \Redis|bool
656647
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
657648
}
658649

659-
public function mget($keys): \Redis|array
660-
{
661-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
662-
}
663-
664650
public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
665651
{
666652
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
15+
/**
16+
* @internal
17+
*/
18+
trait Redis6ProxyTrait
19+
{
20+
public function dump($key): \Redis|false|string
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
23+
}
24+
25+
public function mget($keys): \Redis|array|false
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
28+
}
29+
30+
public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
33+
}
34+
}
35+
} else {
36+
/**
37+
* @internal
38+
*/
39+
trait Redis6ProxyTrait
40+
{
41+
public function dump($key): \Redis|string
42+
{
43+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
44+
}
45+
46+
public function mget($keys): \Redis|array
47+
{
48+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
49+
}
50+
}
51+
}

src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyOb
2828
use LazyProxyTrait {
2929
resetLazyObject as reset;
3030
}
31+
use RedisCluster6ProxyTrait;
3132

3233
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
3334

@@ -96,11 +97,6 @@ public function bgrewriteaof($key_or_address): \RedisCluster|bool
9697
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgrewriteaof(...\func_get_args());
9798
}
9899

99-
public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \RedisCluster|array|false
100-
{
101-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
102-
}
103-
104100
public function bgsave($key_or_address): \RedisCluster|bool
105101
{
106102
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args());
@@ -661,11 +657,6 @@ public function pttl($key): \RedisCluster|false|int
661657
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
662658
}
663659

664-
public function publish($channel, $message): \RedisCluster|bool
665-
{
666-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
667-
}
668-
669660
public function pubsub($key_or_address, ...$values): mixed
670661
{
671662
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
F438
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Symfony\Component\Cache\Traits;
4+
5+
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
6+
/**
7+
* @internal
8+
*/
9+
trait RedisCluster6ProxyTrait
10+
{
11+
public function publish($channel, $message): \RedisCluster|bool|int
12+
{
13+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
14+
}
15+
16+
public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \RedisCluster|array|false
17+
{
18+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->waitaof(...\func_get_args());
19+
}
20+
}
21+
} else {
22+
/**
23+
* @internal
24+
*/
25+
trait RedisCluster6ProxyTrait
26+
{
27+
public function publish($channel, $message): \RedisCluster|bool
28+
{
29+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)
0