ServerExceptionTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Response;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. class ServerExceptionTest extends PredisTestCase
  16. {
  17. const ERR_WRONG_KEY_TYPE = 'ERR Operation against a key holding the wrong kind of value';
  18. /**
  19. * @group disconnected
  20. */
  21. public function testExceptionMessage()
  22. {
  23. $this->setExpectedException('Predis\Response\ServerException', self::ERR_WRONG_KEY_TYPE);
  24. throw new ServerException(self::ERR_WRONG_KEY_TYPE);
  25. }
  26. /**
  27. * @group disconnected
  28. */
  29. public function testExceptionClass()
  30. {
  31. $exception = new ServerException(self::ERR_WRONG_KEY_TYPE);
  32. $this->assertInstanceOf('Predis\Response\ServerException', $exception);
  33. $this->assertInstanceOf('Predis\Response\ErrorInterface', $exception);
  34. $this->assertInstanceOf('Predis\Response\ResponseInterface', $exception);
  35. $this->assertInstanceOf('Predis\PredisException', $exception);
  36. }
  37. /**
  38. * @group disconnected
  39. */
  40. public function testErrorType()
  41. {
  42. $exception = new ServerException(self::ERR_WRONG_KEY_TYPE);
  43. $this->assertEquals('ERR', $exception->getErrorType());
  44. }
  45. /**
  46. * @group disconnected
  47. */
  48. public function testToErrorResponse()
  49. {
  50. $exception = new ServerException(self::ERR_WRONG_KEY_TYPE);
  51. $error = $exception->toErrorResponse();
  52. $this->assertInstanceOf('Predis\Response\Error', $error);
  53. $this->assertEquals($exception->getMessage(), $error->getMessage());
  54. $this->assertEquals($exception->getErrorType(), $error->getErrorType());
  55. }
  56. }