PFADD_Test.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Command\Redis;
  11. /**
  12. * @group commands
  13. * @group realm-hyperloglog
  14. *
  15. * @todo Add integration tests depending on the minor redis version.
  16. */
  17. class PFADD_Test extends PredisCommandTestCase
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function getExpectedCommand()
  23. {
  24. return 'Predis\Command\Redis\PFADD';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. protected function getExpectedId()
  30. {
  31. return 'PFADD';
  32. }
  33. /**
  34. * @group disconnected
  35. */
  36. public function testFilterArguments()
  37. {
  38. $arguments = array('key', 'a', 'b', 'c');
  39. $expected = array('key', 'a', 'b', 'c');
  40. $command = $this->getCommand();
  41. $command->setArguments($arguments);
  42. $this->assertSame($expected, $command->getArguments());
  43. }
  44. /**
  45. * @group disconnected
  46. */
  47. public function testFilterArgumentsFieldsAsSingleArray()
  48. {
  49. $arguments = array('key', array('a', 'b', 'c'));
  50. $expected = array('key', 'a', 'b', 'c');
  51. $command = $this->getCommand();
  52. $command->setArguments($arguments);
  53. $this->assertSame($expected, $command->getArguments());
  54. }
  55. /**
  56. * @group disconnected
  57. */
  58. public function testParseResponse()
  59. {
  60. $command = $this->getCommand();
  61. $this->assertSame(0, $command->parseResponse(0));
  62. $this->assertSame(1, $command->parseResponse(1));
  63. }
  64. /**
  65. * @group connected
  66. * @requiresRedisVersion >= 2.8.9
  67. * @expectedException \Predis\Response\ServerException
  68. * @expectedExceptionMessage Operation against a key holding the wrong kind of value
  69. */
  70. public function testThrowsExceptionOnWrongType()
  71. {
  72. $redis = $this->getClient();
  73. $redis->lpush('metavars', 'foo', 'hoge');
  74. $redis->pfadd('metavars', 'foofoo');
  75. }
  76. }