ListSetTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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;
  11. use PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. * @group commands
  14. * @group realm-list
  15. */
  16. class ListSetTest extends CommandTestCase
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. protected function getExpectedCommand()
  22. {
  23. return 'Predis\Command\ListSet';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function getExpectedId()
  29. {
  30. return 'LSET';
  31. }
  32. /**
  33. * @group disconnected
  34. */
  35. public function testFilterArguments()
  36. {
  37. $arguments = array('key', 0, 'value');
  38. $expected = array('key', 0, 'value');
  39. $command = $this->getCommand();
  40. $command->setArguments($arguments);
  41. $this->assertSame($expected, $command->getArguments());
  42. }
  43. /**
  44. * @group disconnected
  45. */
  46. public function testParseResponse()
  47. {
  48. $this->assertTrue($this->getCommand()->parseResponse(true));
  49. }
  50. /**
  51. * @group connected
  52. */
  53. public function testSetsElementAtSpecifiedIndex()
  54. {
  55. $redis = $this->getClient();
  56. $redis->rpush('letters', 'a', 'b', 'c');
  57. $this->assertTrue($redis->lset('letters', 1, 'B'));
  58. $this->assertSame(array('a', 'B', 'c'), $redis->lrange('letters', 0, -1));
  59. }
  60. /**
  61. * @group connected
  62. * @expectedException Predis\Response\ServerException
  63. * @expectedExceptionMessage ERR index out of range
  64. */
  65. public function testThrowsExceptionOnIndexOutOfRange()
  66. {
  67. $redis = $this->getClient();
  68. $redis->rpush('letters', 'a', 'b', 'c');
  69. $redis->lset('letters', 21, 'z');
  70. }
  71. /**
  72. * @group connected
  73. * @expectedException Predis\Response\ServerException
  74. * @expectedExceptionMessage Operation against a key holding the wrong kind of value
  75. */
  76. public function testThrowsExceptionOnWrongType()
  77. {
  78. $redis = $this->getClient();
  79. $redis->set('metavars', 'foo');
  80. $redis->lset('metavars', 0, 'hoge');
  81. }
  82. }