mirror of
https://github.com/predis/predis.git
synced 2026-10-15 16:26:48 +00:00
abd284c972
* Renamed SingleConnectionInterface to NodeConnectionInterface since this name is better and makes even more sense in the context of cluster and replication scenarios. * Moved specialized aggregate connections (the ones implementing both predis and redis cluster and master/slave replication) in a newly created Predis\Connection\Aggregate sub-namespace. * Removed the "Connection" part from names of aggregate connection interfaces in the Predis\Connection\Aggregate sub-namespace. * Changed "Composable" to "Composite" in the name of interfaces and classes that can use pluggable protocol processors.
121 lines
3.4 KiB
PHP
121 lines
3.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Predis\Protocol\Text;
|
|
|
|
use PredisTestCase;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class ComposableProtocolProcessorTest extends PredisTestCase
|
|
{
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testConstructor()
|
|
{
|
|
$protocol = new ComposableProtocolProcessor();
|
|
|
|
$this->assertInstanceOf(
|
|
'Predis\Protocol\Text\RequestSerializer', $protocol->getRequestSerializer()
|
|
);
|
|
$this->assertInstanceOf(
|
|
'Predis\Protocol\Text\ResponseReader', $protocol->getResponseReader()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
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());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testCustomRequestSerializer()
|
|
{
|
|
$serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface');
|
|
|
|
$protocol = new ComposableProtocolProcessor();
|
|
$protocol->setRequestSerializer($serializer);
|
|
|
|
$this->assertSame($serializer, $protocol->getRequestSerializer());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testCustomResponseReader()
|
|
{
|
|
$reader = $this->getMock('Predis\Protocol\ResponseReaderInterface');
|
|
|
|
$protocol = new ComposableProtocolProcessor();
|
|
$protocol->setResponseReader($reader);
|
|
|
|
$this->assertSame($reader, $protocol->getResponseReader());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testConnectionWrite()
|
|
{
|
|
$serialized = "*1\r\n$4\r\nPING\r\n";
|
|
|
|
$command = $this->getMock('Predis\Command\CommandInterface');
|
|
$connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
|
|
$serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface');
|
|
|
|
$protocol = new ComposableProtocolProcessor($serializer);
|
|
|
|
$connection->expects($this->once())
|
|
->method('writeBuffer')
|
|
->with($this->equalTo($serialized));
|
|
|
|
$serializer->expects($this->once())
|
|
->method('serialize')
|
|
->with($command)
|
|
->will($this->returnValue($serialized));
|
|
|
|
$protocol->write($connection, $command);
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testConnectionRead()
|
|
{
|
|
$serialized = "*1\r\n$4\r\nPING\r\n";
|
|
|
|
$connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
|
|
$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));
|
|
}
|
|
}
|