8000 [Cache] Fix test failure related to Redis6Proxy on appveyor by nicolas-grekas · Pull Request #54639 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Fix test failure related to Redis6Proxy on appveyor #54639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to < 8000 div class="select-menu-header"> Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 11 additions & 52 deletions src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
class RedisProxiesTest extends TestCase
{
/**
* @requires extension redis < 6
* @requires extension redis
*
* @testWith ["Redis"]
* ["RedisCluster"]
*/
public function testRedis5Proxy($class)
public function testRedisProxy($class)
{
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}5Proxy.php");
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$version = version_compare(phpversion('redis'), '6', '>') ? '6' : '5';
$proxy = file_get_contents(\dirname(__DIR__, 2)."/Traits/{$class}{$version}Proxy.php");
$expected = substr($proxy, 0, 4 + strpos($proxy, '[];'));
$methods = [];

foreach ((new \ReflectionClass($class))->getMethods() as $method) {
Expand All @@ -44,9 +45,13 @@ public function testRedis5Proxy($class)
}

uksort($methods, 'strnatcmp');
$proxy .= implode('', $methods)."}\n";
$expected .= implode('', $methods)."}\n";

if (!str_contains($expected, '#[\SensitiveParameter] ')) {
$proxy = str_replace('#[\SensitiveParameter] ', '', $proxy);
}

$this->assertStringEqualsFile(\dirname(__DIR__, 2)."/Traits/{$class}5Proxy.php", $proxy);
$this->assertSame($expected, $proxy);
}

/**
Expand Down Expand Up @@ -77,50 +82,4 @@ public function testRelayProxy()

$this->assertStringEqualsFile(\dirname(__DIR__, 2).'/Traits/RelayProxy.php', $proxy);
}

/**
* @requires extension openssl
*
* @testWith ["Redis", "redis"]
* ["RedisCluster", "redis_cluster"]
*/
public function testRedis6Proxy($class, $stub)
{
if (version_compare(phpversion('redis'), '6.0.2', '>')) {
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/develop/{$stub}.stub.php");
} else {
$stub = file_get_contents("https://raw.githubusercontent.com/phpredis/phpredis/6.0.2/{$stub}.stub.php");
}

$stub = preg_replace('/^class /m', 'return; \0', $stub);
$stub = preg_replace('/^return; class ([a-zA-Z]++)/m', 'interface \1StubInterface', $stub, 1);
$stub = preg_replace('/^ public const .*/m', '', $stub);
eval(substr($stub, 5));

$this->assertEquals(self::dumpMethods(new \ReflectionClass($class.'StubInterface')), self::dumpMethods(new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\%s6Proxy', $class))));
}

private static function dumpMethods(\ReflectionClass $class): string
{
$methods = [];

foreach ($class->getMethods() as $method) {
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
continue;
}

$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
$signature = ProxyHelper::exportSignature($method, false, $args);
$methods[] = "\n ".str_replace('timeout = 0.0', 'timeout = 0', $signature)."\n".<<<EOPHP
{
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
}

EOPHP;
}

usort($methods, 'strnatcmp');

return implode("\n", $methods);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/Redis5Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->append(...\func_get_args());
}

public function auth($auth)
public function auth(#[\SensitiveParameter] $auth)

Check failure on line 84 in src/Symfony/Component/Cache/Traits/Redis5Proxy.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis5Proxy.php:84:5: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis5Proxy::auth with return type '' is different to return type 'bool' of inherited method Redis::auth (see https://psalm.dev/042)

Check failure on line 84 in src/Symfony/Component/Cache/Traits/Redis5Proxy.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis5Proxy.php:84:5: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis5Proxy::auth with return type '' is different to return type 'bool' of inherited method Redis::auth (see https://psalm.dev/042)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->auth(...\func_get_args());
}
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Component/Cache/Traits/Redis6Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use LazyProxyTrait {
resetLazyObject as reset;
}
use Redis6ProxyTrait;

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

Expand Down Expand Up @@ -227,6 +226,11 @@
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->discard(...\func_get_args());
}

public function dump($key): \Redis|string

Check failure on line 229 in src/Symfony/Component/Cache/Traits/Redis6Proxy.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6Proxy.php:229:5: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6Proxy::dump with return type 'Redis|string' is different to return type 'string' of inherited method Redis::dump (see https://psalm.dev/042)

Check failure on line 229 in src/Symfony/Component/Cache/Traits/Redis6Proxy.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Component/Cache/Traits/Redis6Proxy.php:229:5: MethodSignatureMismatch: Method Symfony\Component\Cache\Traits\Redis6Proxy::dump with return type 'Redis|string' is different to return type 'string' of inherited method Redis::dump (see https://psalm.dev/042)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->dump(...\func_get_args());
}

public function echo($str): \Redis|false|string
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
Expand Down Expand Up @@ -647,6 +651,11 @@
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->ltrim(...\func_get_args());
}

public function mget($keys): \Redis|array
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->mget(...\func_get_args());
}

public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $replace = false, #[\SensitiveParameter] $credentials = null): \Redis|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
Expand Down
51 changes: 0 additions & 51 deletions src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisCluster5Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RedisCluster5Proxy extends \RedisCluster implements ResetInterface, LazyOb

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

public function __construct($name, $seeds = null, $timeout = null, $read_timeout = null, $persistent = null, $auth = null)
public function __construct($name, $seeds = null, $timeout = null, $read_timeout = null, $persistent = null, #[\SensitiveParameter] $auth = null)
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->__construct(...\func_get_args());
}
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Cache/Traits/RedisCluster6Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyOb
use LazyProxyTrait {
resetLazyObject as reset;
}
use RedisCluster6ProxyTrait;

private const LAZY_OBJECT_PROPERTY_SCOPES = [];

Expand Down Expand Up @@ -657,6 +656,11 @@ public function pttl($key): \RedisCluster|false|int
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pttl(...\func_get_args());
}

public function publish($channel, $message): \RedisCluster|bool
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->publish(...\func_get_args());
}

public function pubsub($key_or_address, ...$values): mixed
{
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->pubsub(...\func_get_args());
Expand Down
41 changes: 0 additions & 41 deletions src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php

This file was deleted.

Loading
0