IntegerResponseTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 IntegerResponseTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testInteger()
  21. {
  22. $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
  23. $connection
  24. ->expects($this->never())
  25. ->method('readLine');
  26. $connection
  27. ->expects($this->never())
  28. ->method('readBuffer');
  29. $handler = new Handler\IntegerResponse();
  30. $this->assertSame(0, $handler->handle($connection, '0'));
  31. $this->assertSame(1, $handler->handle($connection, '1'));
  32. $this->assertSame(10, $handler->handle($connection, '10'));
  33. $this->assertSame(-10, $handler->handle($connection, '-10'));
  34. }
  35. /**
  36. * @group disconnected
  37. */
  38. public function testNull()
  39. {
  40. $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
  41. $connection
  42. ->expects($this->never())
  43. ->method('readLine');
  44. $connection
  45. ->expects($this->never())
  46. ->method('readBuffer');
  47. $handler = new Handler\IntegerResponse();
  48. $this->assertNull($handler->handle($connection, 'nil'));
  49. }
  50. /**
  51. * @group disconnected
  52. * @expectedException \Predis\Protocol\ProtocolException
  53. * @expectedExceptionMessage Cannot parse 'invalid' as a valid numeric response [tcp://127.0.0.1:6379]
  54. */
  55. public function testInvalid()
  56. {
  57. $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
  58. $connection
  59. ->expects($this->never())
  60. ->method('readLine');
  61. $connection
  62. ->expects($this->never())
  63. ->method('readBuffer');
  64. $handler = new Handler\IntegerResponse();
  65. $handler->handle($connection, 'invalid');
  66. }
  67. }