PFCOUNT_Test.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 PFCOUNT_Test extends PredisCommandTestCase
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function getExpectedCommand()
  23. {
  24. return 'Predis\Command\Redis\PFCOUNT';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. protected function getExpectedId()
  30. {
  31. return 'PFCOUNT';
  32. }
  33. /**
  34. * @group disconnected
  35. */
  36. public function testFilterArguments()
  37. {
  38. $arguments = array('key:1', 'key:2');
  39. $expected = array('key:1', 'key:2');
  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(array('key:1', 'key:2'));
  50. $expected = array('key:1', 'key:2');
  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. $this->assertSame(10, $command->parseResponse(10));
  64. }
  65. /**
  66. * @group connected
  67. * @requiresRedisVersion >= 2.8.9
  68. * @expectedException \Predis\Response\ServerException
  69. * @expectedExceptionMessage Operation against a key holding the wrong kind of value
  70. */
  71. public function testThrowsExceptionOnWrongType()
  72. {
  73. $redis = $this->getClient();
  74. $redis->lpush('metavars', 'foo', 'hoge');
  75. $redis->pfcount('metavars');
  76. }
  77. /**
  78. * @group connected
  79. * @requiresRedisVersion >= 2.8.9
  80. * @expectedException \Predis\Response\ServerException
  81. * @expectedExceptionMessage Operation against a key holding the wrong kind of value
  82. */
  83. public function testThrowsExceptionOnWrongTypeOfAtLeastOneKey()
  84. {
  85. $redis = $this->getClient();
  86. $redis->pfadd('metavars:1', 'foo', 'hoge');
  87. $redis->lpush('metavars:2', 'foofoo');
  88. $redis->pfcount('metavars:1', 'metavars:2');
  89. }
  90. }