diff --git a/lib/Predis/IRedisServerError.php b/lib/Predis/IRedisServerError.php new file mode 100644 index 00000000..cdf4a7f0 --- /dev/null +++ b/lib/Predis/IRedisServerError.php @@ -0,0 +1,8 @@ +read(); - if (isset($reply->skipParse)) { + if ($reply instanceof IReplyObject) { return $reply; } return $command->parseResponse($reply); diff --git a/lib/Predis/ResponseError.php b/lib/Predis/ResponseError.php index e1c18011..135063cd 100644 --- a/lib/Predis/ResponseError.php +++ b/lib/Predis/ResponseError.php @@ -2,32 +2,23 @@ namespace Predis; -class ResponseError { - public $skipParse = true; +class ResponseError implements IRedisServerError { private $_message; - private $_type; public function __construct($message) { $this->_message = $message; - $this->_type = substr($message, 0, strpos($message, ' ')); } - public function __get($property) { - switch ($property) { - case 'error': - return true; - case 'message': - return $this->_message; - case 'type': - return $this->_type; - } + public function getMessage() { + return $this->_message; } - public function __isset($property) { - return $property === 'error'; + public function getErrorType() { + list($errorType, ) = explode(' ', $this->getMessage(), 2); + return $errorType; } public function __toString() { - return $this->_message; + return $this->getMessage(); } } diff --git a/lib/Predis/ResponseQueued.php b/lib/Predis/ResponseQueued.php index cbb9cbe3..d282f28f 100644 --- a/lib/Predis/ResponseQueued.php +++ b/lib/Predis/ResponseQueued.php @@ -2,9 +2,7 @@ namespace Predis; -class ResponseQueued { - public $skipParse = true; - +class ResponseQueued implements IReplyObject { public function __toString() { return 'QUEUED'; } diff --git a/lib/Predis/ServerException.php b/lib/Predis/ServerException.php index 43c3163e..6a6d7304 100644 --- a/lib/Predis/ServerException.php +++ b/lib/Predis/ServerException.php @@ -2,19 +2,13 @@ namespace Predis; -class ServerException extends PredisException { - private $_errorType; - - public function __construct($message) { - parent::__construct($message); - $this->_errorType = substr($message, 0, strpos($message, ' ')); +class ServerException extends PredisException implements IRedisServerError { + public function getErrorType() { + list($errorType, ) = explode(' ', $this->getMessage(), 2); + return $errorType; } public function toResponseError() { return new ResponseError($this->getMessage()); } - - public function getErrorType() { - return $this->_errorType; - } } diff --git a/test/ClientFeaturesTest.php b/test/ClientFeaturesTest.php index b5f41385..de24e3d5 100644 --- a/test/ClientFeaturesTest.php +++ b/test/ClientFeaturesTest.php @@ -157,7 +157,7 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase { function testResponseQueued() { $response = new \Predis\ResponseQueued(); - $this->assertTrue($response->queued); + $this->assertInstanceOf('\Predis\IReplyObject', $response); $this->assertEquals(\Predis\Protocols\Text\TextProtocol::QUEUED, (string)$response); } @@ -168,8 +168,10 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase { $errorMessage = 'ERROR MESSAGE'; $response = new \Predis\ResponseError($errorMessage); - $this->assertTrue($response->error); - $this->assertEquals($errorMessage, $response->message); + $this->assertInstanceOf('\Predis\IReplyObject', $response); + $this->assertInstanceOf('\Predis\IRedisServerError', $response); + + $this->assertEquals($errorMessage, $response->getMessage()); $this->assertEquals($errorMessage, (string)$response); } @@ -309,7 +311,7 @@ class ClientFeaturesTestSuite extends PHPUnit_Framework_TestCase { $connection->writeBytes($rawCmdUnexpected); $errorReply = $reader->read($connection); $this->assertInstanceOf('\Predis\ResponseError', $errorReply); - $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message); + $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->getMessage()); $reader->setHandler( \Predis\Protocols\Text\TextProtocol::PREFIX_ERROR,