CommandTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 PredisTestCase;
  12. /**
  13. *
  14. */
  15. class CommandTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testImplementsCorrectInterface()
  21. {
  22. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  23. $this->assertInstanceOf('Predis\Command\CommandInterface', $command);
  24. }
  25. /**
  26. * @group disconnected
  27. */
  28. public function testGetEmptyArguments()
  29. {
  30. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  31. $this->assertEmpty($command->getArguments());
  32. }
  33. /**
  34. * @group disconnected
  35. */
  36. public function testSetRawArguments()
  37. {
  38. $arguments = array('1st', '2nd', '3rd');
  39. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  40. $command->setRawArguments($arguments);
  41. $this->assertEquals($arguments, $command->getArguments());
  42. }
  43. /**
  44. * @group disconnected
  45. *
  46. * @todo We cannot set an expectation for Command::filterArguments() when we
  47. * invoke Command::setArguments() because it is protected.
  48. */
  49. public function testSetArguments()
  50. {
  51. $arguments = array('1st', '2nd', '3rd');
  52. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  53. $command->setArguments($arguments);
  54. $this->assertEquals($arguments, $command->getArguments());
  55. }
  56. /**
  57. * @group disconnected
  58. */
  59. public function testGetArgumentAtIndex()
  60. {
  61. $arguments = array('1st', '2nd', '3rd');
  62. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  63. $command->setArguments($arguments);
  64. $this->assertEquals($arguments[0], $command->getArgument(0));
  65. $this->assertEquals($arguments[2], $command->getArgument(2));
  66. $this->assertNull($command->getArgument(10));
  67. }
  68. /**
  69. * @group disconnected
  70. */
  71. public function testParseResponse()
  72. {
  73. $response = 'response-buffer';
  74. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  75. $this->assertEquals($response, $command->parseResponse($response));
  76. }
  77. /**
  78. * @group disconnected
  79. */
  80. public function testSetAndGetSlot()
  81. {
  82. $slot = 1024;
  83. $command = $this->getMockForAbstractClass('Predis\Command\Command');
  84. $command->setRawArguments(array('key'));
  85. $this->assertNull($command->getSlot());
  86. $command->setSlot($slot);
  87. $this->assertSame($slot, $command->getSlot());
  88. $command->setArguments(array('key'));
  89. $this->assertNull($command->getSlot());
  90. $command->setSlot($slot);
  91. $command->setRawArguments(array('key'));
  92. $this->assertNull($command->getSlot());
  93. }
  94. /**
  95. * @group disconnected
  96. */
  97. public function testNormalizeArguments()
  98. {
  99. $arguments = array('arg1', 'arg2', 'arg3', 'arg4');
  100. $this->assertSame($arguments, Command::normalizeArguments($arguments));
  101. $this->assertSame($arguments, Command::normalizeArguments(array($arguments)));
  102. $arguments = array(array(), array());
  103. $this->assertSame($arguments, Command::normalizeArguments($arguments));
  104. $arguments = array(new \stdClass());
  105. $this->assertSame($arguments, Command::normalizeArguments($arguments));
  106. }
  107. /**
  108. * @group disconnected
  109. */
  110. public function testNormalizeVariadic()
  111. {
  112. $arguments = array('key', 'value1', 'value2', 'value3');
  113. $this->assertSame($arguments, Command::normalizeVariadic($arguments));
  114. $this->assertSame($arguments, Command::normalizeVariadic(array('key', array('value1', 'value2', 'value3'))));
  115. $arguments = array(new \stdClass());
  116. $this->assertSame($arguments, Command::normalizeVariadic($arguments));
  117. }
  118. }