MultiBulkResponseTest.php 2.5 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\Protocol\Text;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. class MultiBulkResponseTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testMultiBulk()
  21. {
  22. $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
  23. $connection
  24. ->expects($this->once())
  25. ->method('getProtocol')
  26. ->will($this->returnValue(new CompositeProtocolProcessor()));
  27. $connection
  28. ->expects($this->at(1))
  29. ->method('readLine')
  30. ->will($this->returnValue('$3'));
  31. $connection
  32. ->expects($this->at(2))
  33. ->method('readBuffer')
  34. ->will($this->returnValue("foo\r\n"));
  35. $connection
  36. ->expects($this->at(3))
  37. ->method('readLine')
  38. ->will($this->returnValue('$3'));
  39. $connection
  40. ->expects($this->at(4))
  41. ->method('readBuffer')
  42. ->will($this->returnValue("bar\r\n"));
  43. $handler = new Handler\MultiBulkResponse();
  44. $this->assertSame(array('foo', 'bar'), $handler->handle($connection, '2'));
  45. }
  46. /**
  47. * @group disconnected
  48. */
  49. public function testNull()
  50. {
  51. $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
  52. $connection
  53. ->expects($this->never())
  54. ->method('readLine');
  55. $connection
  56. ->expects($this->never())
  57. ->method('readBuffer');
  58. $handler = new Handler\MultiBulkResponse();
  59. $this->assertNull($handler->handle($connection, '-1'));
  60. }
  61. /**
  62. * @group disconnected
  63. * @expectedException \Predis\Protocol\ProtocolException
  64. * @expectedExceptionMessage Cannot parse 'invalid' as a valid length of a multi-bulk response [tcp://127.0.0.1:6379]
  65. */
  66. public function testInvalid()
  67. {
  68. $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
  69. $connection
  70. ->expects($this->never())
  71. ->method('readLine');
  72. $connection
  73. ->expects($this->never())
  74. ->method('readBuffer');
  75. $handler = new Handler\MultiBulkResponse();
  76. $handler->handle($connection, 'invalid');
  77. }
  78. }