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

Skip to content

Commit 0a8b9e5

Browse files
committed
fix Redis 6 proxy tests
1 parent c87e4a1 commit 0a8b9e5

File tree

5 files changed

+90
-32
lines changed

5 files changed

+90
-32
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 & 10 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

@@ -231,11 +232,6 @@ public function discard(): \Redis|bool
231232
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
232233
}
233234

234-
public function dump($key): \Redis|string
235-
{
236-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
237-
}
238-
239235
public function echo($str): \Redis|false|string
240236
{
241237
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
@@ -656,11 +652,6 @@ public function ltrim($key, $start, $end): \Redis|bool
656652
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
657653
}
658654

659-
public function mget($keys): \Redis|array
660-
{
661-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
662-
}
663-
664655
public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
665656
{
666657
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
} else {
31+
/**
32+
* @internal
33+
*/
34+
trait Redis6ProxyTrait
35+
{
36+
public function dump($key): \Redis|string
37+
{
38+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
39+
}
40+
41+
public function mget($keys): \Redis|array
42+
{
43+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
44+
}
45+
}
46+
}

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

Lines changed: 1 addition & 5 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

@@ -661,11 +662,6 @@ public function pttl($key): \RedisCluster|false|int
661662
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
662663
}
663664

664-
public function publish($channel, $message): \RedisCluster|bool
665-
{
666-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
667-
}
668-
669665
public function pubsub($key_or_address, ...$values): mixed
670666
{
671667
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
} else {
17+
/**
18+
* @internal
19+
*/
20+
trait RedisCluster6ProxyTrait
21+
{
22+
public function publish($channel, $message): \RedisCluster|bool
23+
{
24+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)
0