function testResponseReader_OptionExceptionOnError() { $connection = new Predis_Connection(RC::getConnectionParameters()); $responseReader = $connection->getResponseReader(); $connection->rawCommand("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"); $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"; $responseReader->setOption('throw_on_error', false); $errorReply = $connection->rawCommand($rawCmdUnexpected); $this->assertInstanceOf('Predis_ResponseError', $errorReply); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message); $responseReader->setOption('throw_on_error', true); $thrownException = null; try { $connection->rawCommand($rawCmdUnexpected); } catch (Predis_ServerException $exception) { $thrownException = $exception; } $this->assertInstanceOf('Predis_ServerException', $thrownException); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $thrownException->getMessage()); }
public function __construct(Predis_Connection $connection, $size) { $this->_connection = $connection; $this->_reader = $connection->getResponseReader(); $this->_position = 0; $this->_current = $size > 0 ? $this->getValue() : null; $this->_replySize = $size; }
function testResponseReader_OptionExceptionOnError() { $connection = new Predis_Connection(RC::getConnectionParameters()); $responseReader = $connection->getResponseReader(); $connection->rawCommand("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"); $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n"; $responseReader->setHandler(Predis_Protocol::PREFIX_ERROR, new Predis_ResponseErrorSilentHandler()); $errorReply = $connection->rawCommand($rawCmdUnexpected); $this->assertType('Predis_ResponseError', $errorReply); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message); $responseReader->setHandler(Predis_Protocol::PREFIX_ERROR, new Predis_ResponseErrorHandler()); $thrownException = null; try { $connection->rawCommand($rawCmdUnexpected); } catch (Predis_ServerException $exception) { $thrownException = $exception; } $this->assertType('Predis_ServerException', $thrownException); $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $thrownException->getMessage()); }