ResponseMultiBulkHandlerTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 ResponseMultiBulkHandlerTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testMultiBulk()
  21. {
  22. $handler = new ResponseMultiBulkHandler();
  23. $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
  24. $connection->expects($this->once())
  25. ->method('getProtocol')
  26. ->will($this->returnValue(new ComposableTextProtocol()));
  27. $connection->expects($this->at(1))
  28. ->method('readLine')
  29. ->will($this->returnValue("$3"));
  30. $connection->expects($this->at(2))
  31. ->method('readBytes')
  32. ->will($this->returnValue("foo\r\n"));
  33. $connection->expects($this->at(3))
  34. ->method('readLine')
  35. ->will($this->returnValue("$3"));
  36. $connection->expects($this->at(4))
  37. ->method('readBytes')
  38. ->will($this->returnValue("bar\r\n"));
  39. $this->assertSame(array('foo', 'bar'), $handler->handle($connection, '2'));
  40. }
  41. /**
  42. * @group disconnected
  43. */
  44. public function testNull()
  45. {
  46. $handler = new ResponseMultiBulkHandler();
  47. $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
  48. $connection->expects($this->never())->method('readLine');
  49. $connection->expects($this->never())->method('readBytes');
  50. $this->assertNull($handler->handle($connection, '-1'));
  51. }
  52. /**
  53. * @group disconnected
  54. * @expectedException Predis\Protocol\ProtocolException
  55. * @expectedExceptionMessage Cannot parse 'invalid' as multi-bulk length
  56. */
  57. public function testInvalid()
  58. {
  59. $handler = new ResponseMultiBulkHandler();
  60. $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
  61. $connection->expects($this->never())->method('readLine');
  62. $connection->expects($this->never())->method('readBytes');
  63. $handler->handle($connection, 'invalid');
  64. }
  65. }