TextCommandSerializerTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Protocol\Text;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. class TextCommandSerializerTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testSerializerIdWithNoArguments()
  21. {
  22. $serializer = new TextCommandSerializer();
  23. $command = $this->getMock('Predis\Command\CommandInterface');
  24. $command->expects($this->once())
  25. ->method('getId')
  26. ->will($this->returnValue('PING'));
  27. $command->expects($this->once())
  28. ->method('getArguments')
  29. ->will($this->returnValue(array()));
  30. $result = $serializer->serialize($command);
  31. $this->assertSame("*1\r\n$4\r\nPING\r\n", $result);
  32. }
  33. /**
  34. * @group disconnected
  35. */
  36. public function testSerializerIdWithArguments()
  37. {
  38. $serializer = new TextCommandSerializer();
  39. $command = $this->getMock('Predis\Command\CommandInterface');
  40. $command->expects($this->once())
  41. ->method('getId')
  42. ->will($this->returnValue('SET'));
  43. $command->expects($this->once())
  44. ->method('getArguments')
  45. ->will($this->returnValue(array('key', 'value')));
  46. $result = $serializer->serialize($command);
  47. $this->assertSame("*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n", $result);
  48. }
  49. }