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()); RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) { $connection->rawCommand($rawCmdUnexpected); }); }
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); RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) { $connection->rawCommand($rawCmdUnexpected); }); }