ResponseIntegerHandlerTest.php 2.0 KB

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