ResponseIntegerHandlerTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 ResponseIntegerHandlerTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testInteger()
  21. {
  22. $handler = new ResponseIntegerHandler();
  23. $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
  24. $connection->expects($this->never())->method('readLine');
  25. $connection->expects($this->never())->method('readBytes');
  26. $this->assertSame(0, $handler->handle($connection, '0'));
  27. $this->assertSame(1, $handler->handle($connection, '1'));
  28. $this->assertSame(10, $handler->handle($connection, '10'));
  29. $this->assertSame(-10, $handler->handle($connection, '-10'));
  30. }
  31. /**
  32. * @group disconnected
  33. */
  34. public function testNull()
  35. {
  36. $handler = new ResponseIntegerHandler();
  37. $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
  38. $connection->expects($this->never())->method('readLine');
  39. $connection->expects($this->never())->method('readBytes');
  40. $this->assertNull($handler->handle($connection, 'nil'));
  41. }
  42. /**
  43. * @group disconnected
  44. * @expectedException Predis\Protocol\ProtocolException
  45. * @expectedExceptionMessage Cannot parse 'invalid' as numeric response
  46. */
  47. public function testInvalid()
  48. {
  49. $handler = new ResponseIntegerHandler();
  50. $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
  51. $connection->expects($this->never())->method('readLine');
  52. $connection->expects($this->never())->method('readBytes');
  53. $handler->handle($connection, 'invalid');
  54. }
  55. }