Sets the response reader used by the protocol processor.
public setResponseReader ( Predis\Protocol\ResponseReaderInterface $reader ) | ||
$reader | Predis\Protocol\ResponseReaderInterface | Response reader. |
/** * @group disconnected */ public function testCustomResponseReader() { $reader = $this->getMock('Predis\\Protocol\\ResponseReaderInterface'); $protocol = new CompositeProtocolProcessor(); $protocol->setResponseReader($reader); $this->assertSame($reader, $protocol->getResponseReader()); }
/** * @group disconnected */ public function testReadResponse() { $reader = new ResponseReader(); $protocol = new CompositeProtocolProcessor(); $protocol->setResponseReader($reader); $connection = $this->getMock('Predis\\Connection\\CompositeConnectionInterface'); $connection->expects($this->at(0))->method('readLine')->will($this->returnValue('+OK')); $connection->expects($this->at(1))->method('readLine')->will($this->returnValue('-ERR error message')); $connection->expects($this->at(2))->method('readLine')->will($this->returnValue(':2')); $connection->expects($this->at(3))->method('readLine')->will($this->returnValue('$-1')); $connection->expects($this->at(4))->method('readLine')->will($this->returnValue('*-1')); $this->assertEquals('OK', $reader->read($connection)); $this->assertEquals('ERR error message', $reader->read($connection)); $this->assertSame(2, $reader->read($connection)); $this->assertNull($reader->read($connection)); $this->assertNull($reader->read($connection)); }