Skip to content
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

Not working with phpredis #60

Open
nicolashohm opened this issue Oct 18, 2017 · 2 comments
Open

Not working with phpredis #60

nicolashohm opened this issue Oct 18, 2017 · 2 comments

Comments

@nicolashohm
Copy link

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 ]
      }
    }
...
}
@nicolashohm
Copy link
Author

nicolashohm commented Oct 18, 2017

Sorry I didn't read the disclaimer in the README that only predis is supported. But anyway, please see this as a feature request 😉

@TysonAndre
Copy link

TysonAndre commented Feb 21, 2018

Proper reflection signatures were added to phpredis in phpredis/phpredis#1055

TysonAndre@a98c233 seems to be working with 3.1.2 (I haven't checked if errors were suppressed)

NOTE: I haven't gotten around to running the test suites yet, I expect there to be failures to fix

  • I'm instantiating RedisMock directly instead of using RedisMockFactory
  • The isOptional change seems like it could be merged on its own. It's based on pr 48 to this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants