123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace Predis\Protocol\Text;
- use \PHPUnit_Framework_TestCase as StandardTestCase;
- class ComposableProtocolProcessorTest extends StandardTestCase
- {
-
- public function testConstructor()
- {
- $protocol = new ComposableProtocolProcessor();
- $this->assertInstanceOf(
- 'Predis\Protocol\Text\RequestSerializer', $protocol->getRequestSerializer()
- );
- $this->assertInstanceOf(
- 'Predis\Protocol\Text\ResponseReader', $protocol->getResponseReader()
- );
- }
-
- public function testConstructorWithArguments()
- {
- $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface');
- $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface');
- $protocol = new ComposableProtocolProcessor($serializer, $reader);
- $this->assertSame($serializer, $protocol->getRequestSerializer());
- $this->assertSame($reader, $protocol->getResponseReader());
- }
-
- public function testCustomRequestSerializer()
- {
- $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface');
- $protocol = new ComposableProtocolProcessor();
- $protocol->setRequestSerializer($serializer);
- $this->assertSame($serializer, $protocol->getRequestSerializer());
- }
-
- public function testCustomResponseReader()
- {
- $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface');
- $protocol = new ComposableProtocolProcessor();
- $protocol->setResponseReader($reader);
- $this->assertSame($reader, $protocol->getResponseReader());
- }
-
- public function testConnectionWrite()
- {
- $serialized = "*1\r\n$4\r\nPING\r\n";
- $command = $this->getMock('Predis\Command\CommandInterface');
- $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
- $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface');
- $protocol = new ComposableProtocolProcessor($serializer);
- $connection->expects($this->once())
- ->method('writeBytes')
- ->with($this->equalTo($serialized));
- $serializer->expects($this->once())
- ->method('serialize')
- ->with($command)
- ->will($this->returnValue($serialized));
- $protocol->write($connection, $command);
- }
-
- public function testConnectionRead()
- {
- $serialized = "*1\r\n$4\r\nPING\r\n";
- $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
- $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface');
- $protocol = new ComposableProtocolProcessor(null, $reader);
- $reader->expects($this->once())
- ->method('read')
- ->with($connection)
- ->will($this->returnValue('bulk'));
- $this->assertSame('bulk', $protocol->read($connection));
- }
- }
|