We discovered an issue with phpredis.
We wan't to create a Redis mock to inject them into another class that expects an instance of Redis.
Our solution now is to not use the factory but creating RedisMock directly, remove the typehint in our sut and inject the RedisMock directly.
System Informations
OS: Linux
PHP: PHP 7.1.10-1+0~20170929170631.9+jessie~1.gbp501135 (cli)
phpredis: 3.1.2
Reproduce
$factory = new \M6Web\Component\RedisMock\RedisMockFactory();
$myRedisMockClass = $factory->getAdapter(Redis::class, true);
$myRedisMock = new $myRedisMockClass();
$myRedisMock->hSetNx('foo', 'bar', 'baz');
Error
ArgumentCountError: Too few arguments to function M6Web\Component\RedisMock\RedisMock::hsetnx(), 0 passed in vendor/m6web/redis-mock/src/M6Web/Component/RedisMock/RedisMockFactory.php(226) : eval()'d code on line 370 and exactly 3 expected
vendor/m6web/redis-mock/src/M6Web/Component/RedisMock/RedisMock.php:579
More informations
we debugged a bit and found out that the reflection of Redis give no details about the parameters for most of the methods.
php > $ref = new ReflectionClass(Redis::class);
php > echo (string)$ref;
Class [ <internal:redis> class Redis ] {
...
Method [ <internal:redis> public method hGet ] {
}
Method [ <internal:redis> public method hSet ] {
}
Method [ <internal:redis> public method hSetNx ] {
}
Method [ <internal:redis> public method hDel ] {
}
...
Method [ <internal:redis> public method command ] {
}
Method [ <internal:redis> public method scan ] {
- Parameters [3] {
Parameter #0 [ <required> &$i_iterator ]
Parameter #1 [ <optional> $str_pattern ]
Parameter #2 [ <optional> $i_count ]
}
}
Method [ <internal:redis> public method hscan ] {
- Parameters [4] {
Parameter #0 [ <required> $str_key ]
Parameter #1 [ <required> &$i_iterator ]
Parameter #2 [ <optional> $str_pattern ]
Parameter #3 [ <optional> $i_count ]
}
}
...
}
We discovered an issue with phpredis.
We wan't to create a Redis mock to inject them into another class that expects an instance of
Redis.Our solution now is to not use the factory but creating
RedisMockdirectly, remove the typehint in our sut and inject the RedisMock directly.System Informations
OS: Linux
PHP:
PHP 7.1.10-1+0~20170929170631.9+jessie~1.gbp501135 (cli)phpredis: 3.1.2
Reproduce
Error
More informations
we debugged a bit and found out that the reflection of
Redisgive no details about the parameters for most of the methods.