From 95b9f63cab8cf502d0db412543cc2bf2725000bc Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Tue, 10 Dec 2013 21:26:11 +0100 Subject: [PATCH] Rename write and read methods of the composable connection interface. --- .../Connection/ComposableConnectionInterface.php | 11 ++++++----- lib/Predis/Connection/ComposableStreamConnection.php | 6 +++--- lib/Predis/Connection/PhpiredisStreamConnection.php | 2 +- lib/Predis/Connection/StreamConnection.php | 4 ++-- .../Protocol/Text/ComposableProtocolProcessor.php | 2 +- lib/Predis/Protocol/Text/Handler/BulkResponse.php | 2 +- lib/Predis/Protocol/Text/ProtocolProcessor.php | 4 ++-- .../Protocol/Text/ComposableProtocolProcessorTest.php | 2 +- .../Predis/Protocol/Text/Handler/BulkResponseTest.php | 8 ++++---- .../Protocol/Text/Handler/ErrorResponseTest.php | 2 +- .../Protocol/Text/Handler/IntegerResponseTest.php | 6 +++--- .../Protocol/Text/Handler/MultiBulkResponseTest.php | 8 ++++---- .../Protocol/Text/Handler/StatusResponseTest.php | 6 +++--- .../Text/Handler/StreamableMultiBulkResponseTest.php | 4 ++-- tests/Predis/Protocol/Text/ProtocolProcessorTest.php | 2 +- 15 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/Predis/Connection/ComposableConnectionInterface.php b/lib/Predis/Connection/ComposableConnectionInterface.php index 6eb23d28..1e78aaef 100644 --- a/lib/Predis/Connection/ComposableConnectionInterface.php +++ b/lib/Predis/Connection/ComposableConnectionInterface.php @@ -27,18 +27,19 @@ interface ComposableConnectionInterface extends SingleConnectionInterface public function getProtocol(); /** - * Writes the buffer containing a serialized command over the connection. + * Writes the buffer containing over the connection. * - * @param string $buffer Serialized Redis command. + * @param string $buffer String buffer to be sent over the connection. */ - public function writeBytes($buffer); + public function writeBuffer($buffer); /** * Reads the given number of bytes from the connection. * - * @param string + * @param int $length Number of bytes to read from the connection. + * @return string */ - public function readBytes($length); + public function readBuffer($length); /** * Reads a line from the connection. diff --git a/lib/Predis/Connection/ComposableStreamConnection.php b/lib/Predis/Connection/ComposableStreamConnection.php index 73924d2c..6b1f9484 100644 --- a/lib/Predis/Connection/ComposableStreamConnection.php +++ b/lib/Predis/Connection/ComposableStreamConnection.php @@ -48,15 +48,15 @@ class ComposableStreamConnection extends StreamConnection implements ComposableC /** * {@inheritdoc} */ - public function writeBytes($buffer) + public function writeBuffer($buffer) { - parent::writeBytes($buffer); + $this->write($buffer); } /** * {@inheritdoc} */ - public function readBytes($length) + public function readBuffer($length) { if ($length <= 0) { throw new \InvalidArgumentException('Length parameter must be greater than 0'); diff --git a/lib/Predis/Connection/PhpiredisStreamConnection.php b/lib/Predis/Connection/PhpiredisStreamConnection.php index e82c8e64..f6239451 100644 --- a/lib/Predis/Connection/PhpiredisStreamConnection.php +++ b/lib/Predis/Connection/PhpiredisStreamConnection.php @@ -165,7 +165,7 @@ class PhpiredisStreamConnection extends StreamConnection $arguments = $command->getArguments(); array_unshift($arguments, $command->getId()); - $this->writeBytes(phpiredis_format_command($arguments)); + $this->write(phpiredis_format_command($arguments)); } /** diff --git a/lib/Predis/Connection/StreamConnection.php b/lib/Predis/Connection/StreamConnection.php index b366fc7c..8f50b884 100644 --- a/lib/Predis/Connection/StreamConnection.php +++ b/lib/Predis/Connection/StreamConnection.php @@ -151,7 +151,7 @@ class StreamConnection extends AbstractConnection * * @param string $buffer Representation of a command in the Redis wire protocol. */ - protected function writeBytes($buffer) + protected function write($buffer) { $socket = $this->getResource(); @@ -257,6 +257,6 @@ class StreamConnection extends AbstractConnection $buffer .= "\${$arglen}\r\n{$argument}\r\n"; } - $this->writeBytes($buffer); + $this->write($buffer); } } diff --git a/lib/Predis/Protocol/Text/ComposableProtocolProcessor.php b/lib/Predis/Protocol/Text/ComposableProtocolProcessor.php index 934cbca5..96418d72 100644 --- a/lib/Predis/Protocol/Text/ComposableProtocolProcessor.php +++ b/lib/Predis/Protocol/Text/ComposableProtocolProcessor.php @@ -46,7 +46,7 @@ class ComposableProtocolProcessor implements ProtocolProcessorInterface */ public function write(ComposableConnectionInterface $connection, CommandInterface $command) { - $connection->writeBytes($this->serializer->serialize($command)); + $connection->writeBuffer($this->serializer->serialize($command)); } /** diff --git a/lib/Predis/Protocol/Text/Handler/BulkResponse.php b/lib/Predis/Protocol/Text/Handler/BulkResponse.php index b0daec1c..17218fad 100644 --- a/lib/Predis/Protocol/Text/Handler/BulkResponse.php +++ b/lib/Predis/Protocol/Text/Handler/BulkResponse.php @@ -38,7 +38,7 @@ class BulkResponse implements ResponseHandlerInterface } if ($length >= 0) { - return substr($connection->readBytes($length + 2), 0, -2); + return substr($connection->readBuffer($length + 2), 0, -2); } if ($length == -1) { diff --git a/lib/Predis/Protocol/Text/ProtocolProcessor.php b/lib/Predis/Protocol/Text/ProtocolProcessor.php index 47f28c81..9a2937cc 100644 --- a/lib/Predis/Protocol/Text/ProtocolProcessor.php +++ b/lib/Predis/Protocol/Text/ProtocolProcessor.php @@ -45,7 +45,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface public function write(ComposableConnectionInterface $connection, CommandInterface $command) { $request = $this->serializer->serialize($command); - $connection->writeBytes($request); + $connection->writeBuffer($request); } /** @@ -66,7 +66,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface if ($size === -1) { return null; } - return substr($connection->readBytes($size + 2), 0, -2); + return substr($connection->readBuffer($size + 2), 0, -2); case '*': // multi bulk $count = (int) $payload; diff --git a/tests/Predis/Protocol/Text/ComposableProtocolProcessorTest.php b/tests/Predis/Protocol/Text/ComposableProtocolProcessorTest.php index ff7e0e84..5f66f83d 100644 --- a/tests/Predis/Protocol/Text/ComposableProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/ComposableProtocolProcessorTest.php @@ -87,7 +87,7 @@ class ComposableProtocolProcessorTest extends PredisTestCase $protocol = new ComposableProtocolProcessor($serializer); $connection->expects($this->once()) - ->method('writeBytes') + ->method('writeBuffer') ->with($this->equalTo($serialized)); $serializer->expects($this->once()) diff --git a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php index 1a52c7c1..72d94d7c 100644 --- a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php @@ -29,7 +29,7 @@ class BulkResponseTest extends PredisTestCase $connection->expects($this->never())->method('readLine'); $connection->expects($this->once()) - ->method('readBytes') + ->method('readBuffer') ->with($this->equalTo(2)) ->will($this->returnValue("\r\n")); @@ -50,7 +50,7 @@ class BulkResponseTest extends PredisTestCase $connection->expects($this->never())->method('readLine'); $connection->expects($this->once()) - ->method('readBytes') + ->method('readBuffer') ->with($this->equalTo($bulkLengh + 2)) ->will($this->returnValue("$bulk\r\n")); @@ -67,7 +67,7 @@ class BulkResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $this->assertNull($handler->handle($connection, '-1')); } @@ -84,7 +84,7 @@ class BulkResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $handler->handle($connection, 'invalid'); } diff --git a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php index c31977d9..f3bc5ee0 100644 --- a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php @@ -28,7 +28,7 @@ class ErrorResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $message = "ERR Operation against a key holding the wrong kind of value"; $response = $handler->handle($connection, $message); diff --git a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php index 41c5c027..a445c605 100644 --- a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php @@ -28,7 +28,7 @@ class IntegerResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $this->assertSame(0, $handler->handle($connection, '0')); $this->assertSame(1, $handler->handle($connection, '1')); @@ -46,7 +46,7 @@ class IntegerResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $this->assertNull($handler->handle($connection, 'nil')); } @@ -63,7 +63,7 @@ class IntegerResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $handler->handle($connection, 'invalid'); } diff --git a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php index c7d2d36d..79bd8085 100644 --- a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php @@ -36,7 +36,7 @@ class MultiBulkResponseTest extends PredisTestCase ->will($this->returnValue("$3")); $connection->expects($this->at(2)) - ->method('readBytes') + ->method('readBuffer') ->will($this->returnValue("foo\r\n")); $connection->expects($this->at(3)) @@ -44,7 +44,7 @@ class MultiBulkResponseTest extends PredisTestCase ->will($this->returnValue("$3")); $connection->expects($this->at(4)) - ->method('readBytes') + ->method('readBuffer') ->will($this->returnValue("bar\r\n")); $this->assertSame(array('foo', 'bar'), $handler->handle($connection, '2')); @@ -60,7 +60,7 @@ class MultiBulkResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $this->assertNull($handler->handle($connection, '-1')); } @@ -77,7 +77,7 @@ class MultiBulkResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $handler->handle($connection, 'invalid'); } diff --git a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php index fb7ca6e8..ac732f98 100644 --- a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php @@ -28,7 +28,7 @@ class StatusResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $response = $handler->handle($connection, 'OK'); @@ -46,7 +46,7 @@ class StatusResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $response = $handler->handle($connection, 'QUEUED'); @@ -64,7 +64,7 @@ class StatusResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $response = $handler->handle($connection, 'Background saving started'); diff --git a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php index 6d4eee54..64e7ee6c 100644 --- a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php @@ -28,7 +28,7 @@ class StreamableMultiBulkResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $this->assertInstanceOf('Predis\Response\Iterator\MultiBulk', $handler->handle($connection, '1')); } @@ -45,7 +45,7 @@ class StreamableMultiBulkResponseTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->never())->method('readLine'); - $connection->expects($this->never())->method('readBytes'); + $connection->expects($this->never())->method('readBuffer'); $handler->handle($connection, 'invalid'); } diff --git a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php index ea3c23fe..f228f53d 100644 --- a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php @@ -40,7 +40,7 @@ class ProtocolProcessorTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface'); $connection->expects($this->once()) - ->method('writeBytes') + ->method('writeBuffer') ->with($this->equalTo($serialized)); $protocol->write($connection, $command);