Quellcode durchsuchen

Merge branch 'v0.9/protocol-processor-api' into integration

Daniele Alessandri vor 11 Jahren
Ursprung
Commit
bf991a24f3
33 geänderte Dateien mit 335 neuen und 459 gelöschten Zeilen
  1. 5 1
      CHANGELOG.md
  2. 0 7
      lib/Predis/Connection/ComposableConnectionInterface.php
  3. 9 19
      lib/Predis/Connection/ComposableStreamConnection.php
  4. 0 50
      lib/Predis/Protocol/ComposableProtocolInterface.php
  5. 1 2
      lib/Predis/Protocol/ProtocolException.php
  6. 8 8
      lib/Predis/Protocol/ProtocolProcessorInterface.php
  7. 2 2
      lib/Predis/Protocol/RequestSerializerInterface.php
  8. 3 3
      lib/Predis/Protocol/ResponseReaderInterface.php
  9. 99 0
      lib/Predis/Protocol/Text/ComposableProtocolProcessor.php
  10. 0 129
      lib/Predis/Protocol/Text/ComposableTextProtocol.php
  11. 9 14
      lib/Predis/Protocol/Text/Handler/BulkResponse.php
  12. 6 10
      lib/Predis/Protocol/Text/Handler/ErrorResponse.php
  13. 10 15
      lib/Predis/Protocol/Text/Handler/IntegerResponse.php
  14. 10 15
      lib/Predis/Protocol/Text/Handler/MultiBulkResponse.php
  15. 5 5
      lib/Predis/Protocol/Text/Handler/ResponseHandlerInterface.php
  16. 5 5
      lib/Predis/Protocol/Text/Handler/StatusResponse.php
  17. 13 14
      lib/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php
  18. 19 28
      lib/Predis/Protocol/Text/ProtocolProcessor.php
  19. 6 7
      lib/Predis/Protocol/Text/RequestSerializer.php
  20. 26 27
      lib/Predis/Protocol/Text/ResponseReader.php
  21. 1 1
      tests/Predis/Connection/ComposableStreamConnectionTest.php
  22. 3 3
      tests/Predis/Iterator/MultiBulkResponseSimpleTest.php
  23. 3 3
      tests/Predis/Iterator/MultiBulkResponseTupleTest.php
  24. 42 41
      tests/Predis/Protocol/Text/ComposableProtocolProcessorTest.php
  25. 6 6
      tests/Predis/Protocol/Text/Handler/BulkResponseTest.php
  26. 2 2
      tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php
  27. 5 5
      tests/Predis/Protocol/Text/Handler/IntegerResponse.php
  28. 6 6
      tests/Predis/Protocol/Text/Handler/MultiBulkResponse.php
  29. 4 4
      tests/Predis/Protocol/Text/Handler/StatusResponseTest.php
  30. 4 4
      tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php
  31. 6 6
      tests/Predis/Protocol/Text/ProtocolProcessorTest.php
  32. 3 3
      tests/Predis/Protocol/Text/RequestSerializerTest.php
  33. 14 14
      tests/Predis/Protocol/Text/ResponseReaderTest.php

+ 5 - 1
CHANGELOG.md

@@ -5,13 +5,17 @@ v0.9.0 (201x-xx-xx)
 
 - Dropped support for streamable multibulk responses. Actually we still ship the
   iterator response classes just in case anyone would want to build custom stuff
-  at a level lower than the client abstraction.
+  at a level lower than the client abstraction (our standard and composable text
+  protocol processors still handle them and can be used as an example).
 
 - The `Predis\Option` namespace is now known as `Predis\Configuration` and have
   a fully-reworked `Options` class with the ability to lazily initialize values
   using objects that responds to `__invoke()` (not all the kinds of callables)
   even for custom options defined by the user.
 
+- Most classes and interfaces in the `Predis\Protocol` namespace have been moved
+  or renamed while rationalizing the whole API of external protocol processors.
+
 
 v0.8.5 (2013-xx-xx)
 ===============================================================================

+ 0 - 7
lib/Predis/Connection/ComposableConnectionInterface.php

@@ -22,13 +22,6 @@ use Predis\Protocol\ProtocolInterface;
  */
 interface ComposableConnectionInterface extends SingleConnectionInterface
 {
-    /**
-     * Sets the protocol processor used by the connection.
-     *
-     * @param ProtocolInterface $protocol Protocol processor.
-     */
-    public function setProtocol(ProtocolInterface $protocol);
-
     /**
      * Gets the protocol processor used by the connection.
      */

+ 9 - 19
lib/Predis/Connection/ComposableStreamConnection.php

@@ -12,8 +12,8 @@
 namespace Predis\Connection;
 
 use Predis\Command\CommandInterface;
-use Predis\Protocol\ProtocolInterface;
-use Predis\Protocol\Text\TextProtocol;
+use Predis\Protocol\ProtocolProcessorInterface;
+use Predis\Protocol\Text\ProtocolProcessor as TextProtocolProcessor;
 
 /**
  * Connection abstraction to Redis servers based on PHP's stream that uses an
@@ -23,28 +23,18 @@ use Predis\Protocol\Text\TextProtocol;
  */
 class ComposableStreamConnection extends StreamConnection implements ComposableConnectionInterface
 {
-    private $protocol;
+    protected $protocol;
 
     /**
      * @param ConnectionParametersInterface $parameters Parameters used to initialize the connection.
-     * @param ProtocolInterface $protocol A protocol processor.
+     * @param ProtocolProcessorInterface $protocol Protocol processor.
      */
-    public function __construct(ConnectionParametersInterface $parameters, ProtocolInterface $protocol = null)
-    {
+    public function __construct(
+        ConnectionParametersInterface $parameters,
+        ProtocolProcessorInterface $protocol = null
+    ) {
         $this->parameters = $this->checkParameters($parameters);
-        $this->protocol = $protocol ?: new TextProtocol();
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setProtocol(ProtocolInterface $protocol)
-    {
-        if ($protocol === null) {
-            throw new \InvalidArgumentException("The protocol instance cannot be a null value");
-        }
-
-        $this->protocol = $protocol;
+        $this->protocol = $protocol ?: new TextProtocolProcessor();
     }
 
     /**

+ 0 - 50
lib/Predis/Protocol/ComposableProtocolInterface.php

@@ -1,50 +0,0 @@
-<?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;
-
-/**
- * Interface that defines a customizable protocol processor that serializes
- * Redis commands and parses replies returned by the server to PHP objects
- * using a pluggable set of classes defining the underlying wire protocol.
- *
- * @author Daniele Alessandri <suppakilla@gmail.com>
- */
-interface ComposableProtocolInterface extends ProtocolInterface
-{
-    /**
-     * Sets the command serializer to be used by the protocol processor.
-     *
-     * @param CommandSerializerInterface $serializer Command serializer.
-     */
-    public function setSerializer(CommandSerializerInterface $serializer);
-
-    /**
-     * Returns the command serializer used by the protocol processor.
-     *
-     * @return CommandSerializerInterface
-     */
-    public function getSerializer();
-
-    /**
-     * Sets the response reader to be used by the protocol processor.
-     *
-     * @param ResponseReaderInterface $reader Response reader.
-     */
-    public function setReader(ResponseReaderInterface $reader);
-
-    /**
-     * Returns the response reader used by the protocol processor.
-     *
-     * @return ResponseReaderInterface
-     */
-    public function getReader();
-}

+ 1 - 2
lib/Predis/Protocol/ProtocolException.php

@@ -14,8 +14,7 @@ namespace Predis\Protocol;
 use Predis\CommunicationException;
 
 /**
- * Exception class that identifies errors encountered while
- * handling the Redis wire protocol.
+ * Errors encountered while handling the wire protocol.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */

+ 8 - 8
lib/Predis/Protocol/ProtocolInterface.php → lib/Predis/Protocol/ProtocolProcessorInterface.php

@@ -15,15 +15,15 @@ use Predis\Command\CommandInterface;
 use Predis\Connection\ComposableConnectionInterface;
 
 /**
- * Interface that defines a protocol processor that serializes Redis commands
- * and parses replies returned by the server to PHP objects.
+ * Defines a pluggable protocol processor capable of serializing commands and
+ * deserializing responses into PHP objects directly from a connection.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-interface ProtocolInterface extends ResponseReaderInterface
+interface ProtocolProcessorInterface
 {
     /**
-     * Writes a Redis command on the specified connection.
+     * Writes a command to the specified connection.
      *
      * @param ComposableConnectionInterface $connection Connection to Redis.
      * @param CommandInterface $command Redis command.
@@ -31,10 +31,10 @@ interface ProtocolInterface extends ResponseReaderInterface
     public function write(ComposableConnectionInterface $connection, CommandInterface $command);
 
     /**
-     * Sets the options for the protocol processor.
+     * Reads a response from the specified connection.
      *
-     * @param string $option Name of the option.
-     * @param mixed $value Value of the option.
+     * @param ComposableConnectionInterface $connection Connection to Redis.
+     * @return mixed
      */
-    public function setOption($option, $value);
+    public function read(ComposableConnectionInterface $connection);
 }

+ 2 - 2
lib/Predis/Protocol/CommandSerializerInterface.php → lib/Predis/Protocol/RequestSerializerInterface.php

@@ -14,11 +14,11 @@ namespace Predis\Protocol;
 use Predis\Command\CommandInterface;
 
 /**
- * Interface that defines a custom serializer for Redis commands.
+ * Defines a pluggable serializer for Redis commands.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-interface CommandSerializerInterface
+interface RequestSerializerInterface
 {
     /**
      * Serializes a Redis command.

+ 3 - 3
lib/Predis/Protocol/ResponseReaderInterface.php

@@ -14,15 +14,15 @@ namespace Predis\Protocol;
 use Predis\Connection\ComposableConnectionInterface;
 
 /**
- * Interface that defines a response reader able to parse replies returned by
- * Redis and deserialize them to PHP objects.
+ * Defines a pluggable reader capable of parsing responses returned by Redis and
+ * deserializing them to PHP objects.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
 interface ResponseReaderInterface
 {
     /**
-     * Reads replies from a connection to Redis and deserializes them.
+     * Reads a response from the connection.
      *
      * @param ComposableConnectionInterface $connection Connection to Redis.
      * @return mixed

+ 99 - 0
lib/Predis/Protocol/Text/ComposableProtocolProcessor.php

@@ -0,0 +1,99 @@
+<?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 Predis\Command\CommandInterface;
+use Predis\Connection\ComposableConnectionInterface;
+use Predis\Protocol\ProtocolProcessorInterface;
+use Predis\Protocol\RequestSerializerInterface;
+use Predis\Protocol\ResponseReaderInterface;
+
+/**
+ * Composable protocol processor for the standard Redis wire protocol using
+ * pluggable handlers to serialize requests and deserialize responses.
+ *
+ * @link http://redis.io/topics/protocol
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ */
+class ComposableProtocolProcessor implements ProtocolProcessorInterface
+{
+    protected $serializer;
+    protected $reader;
+
+    /**
+     * @param RequestSerializerInterface $serializer Request serializer.
+     * @param ResponseReaderInterface $reader Response reader.
+     */
+    public function __construct(
+        RequestSerializerInterface $serializer = null,
+        ResponseReaderInterface $reader = null
+    ) {
+        $this->setRequestSerializer($serializer ?: new RequestSerializer());
+        $this->setResponseReader($reader ?: new ResponseReader());
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function write(ComposableConnectionInterface $connection, CommandInterface $command)
+    {
+        $connection->writeBytes($this->serializer->serialize($command));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function read(ComposableConnectionInterface $connection)
+    {
+        return $this->reader->read($connection);
+    }
+
+    /**
+     * Sets the request serializer used by the protocol processor.
+     *
+     * @param RequestSerializerInterface $serializer Request serializer.
+     */
+    public function setRequestSerializer(RequestSerializerInterface $serializer)
+    {
+        $this->serializer = $serializer;
+    }
+
+    /**
+     * Returns the request serializer used by the protocol processor.
+     *
+     * @return RequestSerializerInterface
+     */
+    public function getRequestSerializer()
+    {
+        return $this->serializer;
+    }
+
+    /**
+     * Sets the response reader used by the protocol processor.
+     *
+     * @param ResponseReaderInterface $reader Response reader.
+     */
+    public function setResponseReader(ResponseReaderInterface $reader)
+    {
+        $this->reader = $reader;
+    }
+
+    /**
+     * Returns the Response reader used by the protocol processor.
+     *
+     * @return ResponseReaderInterface
+     */
+    public function getResponseReader()
+    {
+        return $this->reader;
+    }
+}

+ 0 - 129
lib/Predis/Protocol/Text/ComposableTextProtocol.php

@@ -1,129 +0,0 @@
-<?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 Predis\Command\CommandInterface;
-use Predis\Connection\ComposableConnectionInterface;
-use Predis\Protocol\ResponseReaderInterface;
-use Predis\Protocol\CommandSerializerInterface;
-use Predis\Protocol\ComposableProtocolInterface;
-
-/**
- * Implements a customizable protocol processor that uses the standard Redis
- * wire protocol to serialize Redis commands and parse replies returned by
- * the server using a pluggable set of classes.
- *
- * @link http://redis.io/topics/protocol
- * @author Daniele Alessandri <suppakilla@gmail.com>
- */
-class ComposableTextProtocol implements ComposableProtocolInterface
-{
-    private $serializer;
-    private $reader;
-
-    /**
-     * @param array $options Set of options used to initialize the protocol processor.
-     */
-    public function __construct(Array $options = array())
-    {
-        $this->setSerializer(new TextCommandSerializer());
-        $this->setReader(new TextResponseReader());
-
-        if (count($options) > 0) {
-            $this->initializeOptions($options);
-        }
-    }
-
-    /**
-     * Initializes the protocol processor using a set of options.
-     *
-     * @param array $options Set of options.
-     */
-    private function initializeOptions(Array $options)
-    {
-        foreach ($options as $k => $v) {
-            $this->setOption($k, $v);
-        }
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setOption($option, $value)
-    {
-        switch ($option) {
-            case 'iterable_multibulk':
-                $handler = $value ? new ResponseMultiBulkStreamHandler() : new ResponseMultiBulkHandler();
-                $this->reader->setHandler(TextProtocol::PREFIX_MULTI_BULK, $handler);
-                break;
-
-            default:
-                throw new \InvalidArgumentException("The option $option is not supported by the current protocol");
-        }
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function serialize(CommandInterface $command)
-    {
-        return $this->serializer->serialize($command);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function write(ComposableConnectionInterface $connection, CommandInterface $command)
-    {
-        $connection->writeBytes($this->serializer->serialize($command));
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function read(ComposableConnectionInterface $connection)
-    {
-        return $this->reader->read($connection);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setSerializer(CommandSerializerInterface $serializer)
-    {
-        $this->serializer = $serializer;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getSerializer()
-    {
-        return $this->serializer;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setReader(ResponseReaderInterface $reader)
-    {
-        $this->reader = $reader;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getReader()
-    {
-        return $this->reader;
-    }
-}

+ 9 - 14
lib/Predis/Protocol/Text/ResponseBulkHandler.php → lib/Predis/Protocol/Text/Handler/BulkResponse.php

@@ -9,36 +9,31 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol\Text;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\CommunicationException;
 use Predis\Connection\ComposableConnectionInterface;
 use Predis\Protocol\ProtocolException;
-use Predis\Protocol\ResponseHandlerInterface;
 
 /**
- * Implements a response handler for bulk replies using the standard wire
- * protocol defined by Redis.
+ * Handler for the bulk response type in the standard Redis wire protocol.
+ * It translates the payload to a string or a NULL.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ResponseBulkHandler implements ResponseHandlerInterface
+class BulkResponse implements ResponseHandlerInterface
 {
     /**
-     * Handles a bulk reply returned by Redis.
-     *
-     * @param ComposableConnectionInterface $connection Connection to Redis.
-     * @param string $lengthString Bytes size of the bulk reply.
-     * @return string
+     * {@inheritdoc}
      */
-    public function handle(ComposableConnectionInterface $connection, $lengthString)
+    public function handle(ComposableConnectionInterface $connection, $payload)
     {
-        $length = (int) $lengthString;
+        $length = (int) $payload;
 
-        if ("$length" !== $lengthString) {
+        if ("$length" !== $payload) {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$lengthString' as bulk length"
+                $connection, "Cannot parse '$payload' as the length of the bulk response"
             ));
         }
 

+ 6 - 10
lib/Predis/Protocol/Text/ResponseErrorHandler.php → lib/Predis/Protocol/Text/Handler/ErrorResponse.php

@@ -9,29 +9,25 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol\Text;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\ResponseError;
 use Predis\Connection\ComposableConnectionInterface;
-use Predis\Protocol\ResponseHandlerInterface;
 
 /**
- * Implements a response handler for error replies using the standard wire
- * protocol defined by Redis.
- *
- * This handler returns a reply object to notify the user that an error has
- * occurred on the server.
+ * Handler for the error response type in the standard Redis wire protocol.
+ * It translates the payload to a complex response object for Predis.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ResponseErrorHandler implements ResponseHandlerInterface
+class ErrorResponse implements ResponseHandlerInterface
 {
     /**
      * {@inheritdoc}
      */
-    public function handle(ComposableConnectionInterface $connection, $errorMessage)
+    public function handle(ComposableConnectionInterface $connection, $payload)
     {
-        return new ResponseError($errorMessage);
+        return new ResponseError($payload);
     }
 }

+ 10 - 15
lib/Predis/Protocol/Text/ResponseIntegerHandler.php → lib/Predis/Protocol/Text/Handler/IntegerResponse.php

@@ -9,38 +9,33 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol\Text;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\CommunicationException;
 use Predis\Connection\ComposableConnectionInterface;
 use Predis\Protocol\ProtocolException;
-use Predis\Protocol\ResponseHandlerInterface;
 
 /**
- * Implements a response handler for integer replies using the standard wire
- * protocol defined by Redis.
+ * Handler for the integer response type in the standard Redis wire protocol.
+ * It translates the payload an integer or NULL.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ResponseIntegerHandler implements ResponseHandlerInterface
+class IntegerResponse implements ResponseHandlerInterface
 {
     /**
-     * Handles an integer reply returned by Redis.
-     *
-     * @param ComposableConnectionInterface $connection Connection to Redis.
-     * @param string $number String representation of an integer.
-     * @return int
+     * {@inheritdoc}
      */
-    public function handle(ComposableConnectionInterface $connection, $number)
+    public function handle(ComposableConnectionInterface $connection, $payload)
     {
-        if (is_numeric($number)) {
-            return (int) $number;
+        if (is_numeric($payload)) {
+            return (int) $payload;
         }
 
-        if ($number !== 'nil') {
+        if ($payload !== 'nil') {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$number' as numeric response"
+                $connection, "Cannot parse '$payload' as a numeric response"
             ));
         }
 

+ 10 - 15
lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php → lib/Predis/Protocol/Text/Handler/MultiBulkResponse.php

@@ -9,36 +9,31 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol\Text;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\CommunicationException;
 use Predis\Connection\ComposableConnectionInterface;
 use Predis\Protocol\ProtocolException;
-use Predis\Protocol\ResponseHandlerInterface;
 
 /**
- * Implements a response handler for multi-bulk replies using the standard
- * wire protocol defined by Redis.
+ * Handler for the multibulk response type in the standard Redis wire protocol.
+ * It returns multibulk responses as PHP arrays.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ResponseMultiBulkHandler implements ResponseHandlerInterface
+class MultiBulkResponse implements ResponseHandlerInterface
 {
     /**
-     * Handles a multi-bulk reply returned by Redis.
-     *
-     * @param ComposableConnectionInterface $connection Connection to Redis.
-     * @param string $lengthString Number of items in the multi-bulk reply.
-     * @return array
+     * {@inheritdoc}
      */
-    public function handle(ComposableConnectionInterface $connection, $lengthString)
+    public function handle(ComposableConnectionInterface $connection, $payload)
     {
-        $length = (int) $lengthString;
+        $length = (int) $payload;
 
-        if ("$length" !== $lengthString) {
+        if ("$length" !== $payload) {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$lengthString' as multi-bulk length"
+                $connection, "Cannot parse '$payload' as the length of the multibulk response"
             ));
         }
 
@@ -50,7 +45,7 @@ class ResponseMultiBulkHandler implements ResponseHandlerInterface
 
         if ($length > 0) {
             $handlersCache = array();
-            $reader = $connection->getProtocol()->getReader();
+            $reader = $connection->getProtocol()->getResponseReader();
 
             for ($i = 0; $i < $length; $i++) {
                 $header = $connection->readLine();

+ 5 - 5
lib/Predis/Protocol/ResponseHandlerInterface.php → lib/Predis/Protocol/Text/Handler/ResponseHandlerInterface.php

@@ -9,23 +9,23 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\Connection\ComposableConnectionInterface;
 
 /**
- * Interface that defines an handler able to parse a reply.
+ * Defines a pluggable handler used to parse a particular type of response.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
 interface ResponseHandlerInterface
 {
     /**
-     * Parses a type of reply returned by Redis and reads more data from the
-     * connection if needed.
+     * Deserializes the response returned by Redis and reads more data from the
+     * connection when needed.
      *
      * @param ComposableConnectionInterface $connection Connection to Redis.
-     * @param string $payload Initial payload of the reply.
+     * @param string $payload Raw payload.
      * @return mixed
      */
     function handle(ComposableConnectionInterface $connection, $payload);

+ 5 - 5
lib/Predis/Protocol/Text/ResponseStatusHandler.php → lib/Predis/Protocol/Text/Handler/StatusResponse.php

@@ -9,20 +9,20 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol\Text;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\ResponseQueued;
 use Predis\Connection\ComposableConnectionInterface;
-use Predis\Protocol\ResponseHandlerInterface;
 
 /**
- * Implements a response handler for status replies using the standard wire
- * protocol defined by Redis.
+ * Handler for the status response type in the standard Redis wire protocol.
+ * It translates certain classes of status response to PHP objects or just
+ * returns the payload as a string.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ResponseStatusHandler implements ResponseHandlerInterface
+class StatusResponse implements ResponseHandlerInterface
 {
     /**
      * {@inheritdoc}

+ 13 - 14
lib/Predis/Protocol/Text/ResponseMultiBulkStreamHandler.php → lib/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php

@@ -9,37 +9,36 @@
  * file that was distributed with this source code.
  */
 
-namespace Predis\Protocol\Text;
+namespace Predis\Protocol\Text\Handler;
 
 use Predis\CommunicationException;
 use Predis\Connection\ComposableConnectionInterface;
 use Predis\Iterator\MultiBulkResponseSimple;
 use Predis\Protocol\ProtocolException;
-use Predis\Protocol\ResponseHandlerInterface;
 
 /**
- * Implements a response handler for iterable multi-bulk replies using the
- * standard wire protocol defined by Redis.
+ * Handler for the multibulk response type in the standard Redis wire protocol.
+ * It returns multibulk responses as iterators that can stream bulk elements.
+ *
+ * Please note that streamable multibulk replies are not globally supported
+ * by the abstractions built-in into Predis such as for transactions or
+ * pipelines. Use them with care!
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ResponseMultiBulkStreamHandler implements ResponseHandlerInterface
+class StreamableMultiBulkResponse implements ResponseHandlerInterface
 {
     /**
-     * Handles a multi-bulk reply returned by Redis in a streamable fashion.
-     *
-     * @param ComposableConnectionInterface $connection Connection to Redis.
-     * @param string $lengthString Number of items in the multi-bulk reply.
-     * @return MultiBulkResponseSimple
+     * {@inheritdoc}
      */
-    public function handle(ComposableConnectionInterface $connection, $lengthString)
+    public function handle(ComposableConnectionInterface $connection, $payload)
     {
-        $length = (int) $lengthString;
+        $length = (int) $payload;
 
-        if ("$length" != $lengthString) {
+        if ("$length" != $payload) {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$lengthString' as multi-bulk length"
+                $connection, "Cannot parse '$payload' as the length of the multibulk response"
             ));
         }
 

+ 19 - 28
lib/Predis/Protocol/Text/TextProtocol.php → lib/Predis/Protocol/Text/ProtocolProcessor.php

@@ -18,32 +18,18 @@ use Predis\Command\CommandInterface;
 use Predis\Connection\ComposableConnectionInterface;
 use Predis\Iterator\MultiBulkResponseSimple;
 use Predis\Protocol\ProtocolException;
-use Predis\Protocol\ProtocolInterface;
+use Predis\Protocol\ProtocolProcessorInterface;
 
 /**
- * Implements a protocol processor for the standard wire protocol defined by Redis.
+ * Protocol processor for the standard Redis wire protocol.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class TextProtocol implements ProtocolInterface
+class ProtocolProcessor implements ProtocolProcessorInterface
 {
-    const NEWLINE = "\r\n";
-    const OK      = 'OK';
-    const ERROR   = 'ERR';
-    const QUEUED  = 'QUEUED';
-    const NULL    = 'nil';
-
-    const PREFIX_STATUS     = '+';
-    const PREFIX_ERROR      = '-';
-    const PREFIX_INTEGER    = ':';
-    const PREFIX_BULK       = '$';
-    const PREFIX_MULTI_BULK = '*';
-
-    const BUFFER_SIZE = 4096;
-
-    private $mbiterable;
-    private $serializer;
+    protected $mbiterable;
+    protected $serializer;
 
     /**
      *
@@ -51,7 +37,7 @@ class TextProtocol implements ProtocolInterface
     public function __construct()
     {
         $this->mbiterable = false;
-        $this->serializer = new TextCommandSerializer();
+        $this->serializer = new RequestSerializer();
     }
 
     /**
@@ -59,7 +45,8 @@ class TextProtocol implements ProtocolInterface
      */
     public function write(ComposableConnectionInterface $connection, CommandInterface $command)
     {
-        $connection->writeBytes($this->serializer->serialize($command));
+        $request = $this->serializer->serialize($command);
+        $connection->writeBytes($request);
     }
 
     /**
@@ -123,14 +110,18 @@ class TextProtocol implements ProtocolInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Enables or disables returning multibulk responses as specialized PHP
+     * iterators used to stream bulk elements of a multibulk response instead
+     * returning a plain array.
+     *
+     * Please note that streamable multibulk replies are not globally supported
+     * by the abstractions built-in into Predis such as for transactions or
+     * pipelines. Use them with care!
+     *
+     * @param bool $value Enable or disable streamable multibulk responses.
      */
-    public function setOption($option, $value)
+    public function useIterableMultibulk($value)
     {
-        switch ($option) {
-            case 'iterable_multibulk':
-                $this->mbiterable = (bool) $value;
-                break;
-        }
+        $this->mbiterable = (bool) $value;
     }
 }

+ 6 - 7
lib/Predis/Protocol/Text/TextCommandSerializer.php → lib/Predis/Protocol/Text/RequestSerializer.php

@@ -12,29 +12,28 @@
 namespace Predis\Protocol\Text;
 
 use Predis\Command\CommandInterface;
-use Predis\Protocol\CommandSerializerInterface;
+use Predis\Protocol\RequestSerializerInterface;
 
 /**
- * Implements a pluggable command serializer using the standard  wire protocol
- * defined by Redis.
+ * Request serializer for the standard Redis wire protocol.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class TextCommandSerializer implements CommandSerializerInterface
+class RequestSerializer implements RequestSerializerInterface
 {
     /**
      * {@inheritdoc}
      */
     public function serialize(CommandInterface $command)
     {
-        $commandId = $command->getId();
+        $commandID = $command->getId();
         $arguments = $command->getArguments();
 
-        $cmdlen = strlen($commandId);
+        $cmdlen = strlen($commandID);
         $reqlen = count($arguments) + 1;
 
-        $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandId}\r\n";
+        $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n";
 
         for ($i = 0; $i < $reqlen - 1; $i++) {
             $argument = $arguments[$i];

+ 26 - 27
lib/Predis/Protocol/Text/TextResponseReader.php → lib/Predis/Protocol/Text/ResponseReader.php

@@ -14,19 +14,17 @@ namespace Predis\Protocol\Text;
 use Predis\CommunicationException;
 use Predis\Connection\ComposableConnectionInterface;
 use Predis\Protocol\ProtocolException;
-use Predis\Protocol\ResponseHandlerInterface;
 use Predis\Protocol\ResponseReaderInterface;
 
 /**
- * Implements a pluggable response reader using the standard wire protocol
- * defined by Redis.
+ * Response reader for the standard Redis wire protocol.
  *
  * @link http://redis.io/topics/protocol
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class TextResponseReader implements ResponseReaderInterface
+class ResponseReader implements ResponseReaderInterface
 {
-    private $handlers;
+    protected $handlers;
 
     /**
      *
@@ -37,37 +35,36 @@ class TextResponseReader implements ResponseReaderInterface
     }
 
     /**
-     * Returns the default set of response handlers for all the type of replies
-     * that can be returned by Redis.
+     * Returns the default handlers for the supported type of responses.
+     *
+     * @return array
      */
-    private function getDefaultHandlers()
+    protected function getDefaultHandlers()
     {
         return array(
-            TextProtocol::PREFIX_STATUS     => new ResponseStatusHandler(),
-            TextProtocol::PREFIX_ERROR      => new ResponseErrorHandler(),
-            TextProtocol::PREFIX_INTEGER    => new ResponseIntegerHandler(),
-            TextProtocol::PREFIX_BULK       => new ResponseBulkHandler(),
-            TextProtocol::PREFIX_MULTI_BULK => new ResponseMultiBulkHandler(),
+            '+' => new Handler\StatusResponse(),
+            '-' => new Handler\ErrorResponse(),
+            ':' => new Handler\IntegerResponse(),
+            '$' => new Handler\BulkResponse(),
+            '*' => new Handler\MultiBulkResponse(),
         );
     }
 
     /**
-     * Sets a response handler for a certain prefix that identifies a type of
-     * reply that can be returned by Redis.
+     * Sets the handler for the specified prefix identifying the response type.
      *
-     * @param string $prefix Identifier for a type of reply.
-     * @param ResponseHandlerInterface $handler Response handler for the reply.
+     * @param string $prefix Identifier of the type of response.
+     * @param Handler\ResponseHandlerInterface $handler Response handler.
      */
-    public function setHandler($prefix, ResponseHandlerInterface $handler)
+    public function setHandler($prefix, Handler\ResponseHandlerInterface $handler)
     {
         $this->handlers[$prefix] = $handler;
     }
 
     /**
-     * Returns the response handler associated to a certain type of reply that
-     * can be returned by Redis.
+     * Returns the response handler associated to a certain type of response.
      *
-     * @param string $prefix Identifier for a type of reply.
+     * @param string $prefix Identifier of the type of response.
      * @return ResponseHandlerInterface
      */
     public function getHandler($prefix)
@@ -85,13 +82,13 @@ class TextResponseReader implements ResponseReaderInterface
         $header = $connection->readLine();
 
         if ($header === '') {
-            $this->protocolError($connection, 'Unexpected empty header');
+            $this->onProtocolError($connection, 'Unexpected empty header');
         }
 
         $prefix = $header[0];
 
         if (!isset($this->handlers[$prefix])) {
-            $this->protocolError($connection, "Unknown prefix: '$prefix'");
+            $this->onProtocolError($connection, "Unknown prefix: '$prefix'");
         }
 
         $handler = $this->handlers[$prefix];
@@ -100,14 +97,16 @@ class TextResponseReader implements ResponseReaderInterface
     }
 
     /**
-     * Helper method used to handle a protocol error generated while reading a
-     * reply from a connection to Redis.
+     * Handles protocol errors generated while reading responses from the
+     * connection.
      *
      * @param ComposableConnectionInterface $connection Connection to Redis that generated the error.
      * @param string $message Error message.
      */
-    private function protocolError(ComposableConnectionInterface $connection, $message)
+    protected function onProtocolError(ComposableConnectionInterface $connection, $message)
     {
-        CommunicationException::handle(new ProtocolException($connection, $message));
+        CommunicationException::handle(
+            new ProtocolException($connection, $message)
+        );
     }
 }

+ 1 - 1
tests/Predis/Connection/ComposableStreamConnectionTest.php

@@ -75,7 +75,7 @@ class ComposableStreamConnectionTest extends ConnectionTestCase
     public function testReadsMultibulkRepliesAsIterators()
     {
         $connection = $this->getConnection($profile, true);
-        $connection->getProtocol()->setOption('iterable_multibulk', true);
+        $connection->getProtocol()->useIterableMultibulk(true);
 
         $connection->executeCommand($profile->createCommand('rpush', array('metavars', 'foo', 'hoge', 'lol')));
         $connection->writeCommand($profile->createCommand('lrange', array('metavars', 0, -1)));

+ 3 - 3
tests/Predis/Iterator/MultiBulkResponseSimpleTest.php

@@ -16,7 +16,7 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 use Predis\Client;
 use Predis\Connection\ComposableStreamConnection;
 use Predis\Connection\ConnectionParameters;
-use Predis\Protocol\Text\TextProtocol;
+use Predis\Protocol\Text\ProtocolProcessor as TextProtocolProcessor;
 
 /**
  * @group realm-iterators
@@ -130,8 +130,8 @@ class MultiBulkResponseSimpleTest extends StandardTestCase
             'profile' => REDIS_SERVER_VERSION,
         );
 
-        $protocol = new TextProtocol();
-        $protocol->setOption('iterable_multibulk', true);
+        $protocol = new TextProtocolProcessor();
+        $protocol->useIterableMultibulk(true);
 
         $connection = new ComposableStreamConnection($parameters, $protocol);
 

+ 3 - 3
tests/Predis/Iterator/MultiBulkResponseTupleTest.php

@@ -16,7 +16,7 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 use Predis\Client;
 use Predis\Connection\ComposableStreamConnection;
 use Predis\Connection\ConnectionParameters;
-use Predis\Protocol\Text\TextProtocol;
+use Predis\Protocol\Text\ProtocolProcessor as TextProtocolProcessor;
 
 /**
  * @group realm-iterators
@@ -116,8 +116,8 @@ class MultiBulkResponseTupleTest extends StandardTestCase
             'profile' => REDIS_SERVER_VERSION,
         );
 
-        $protocol = new TextProtocol();
-        $protocol->setOption('iterable_multibulk', true);
+        $protocol = new TextProtocolProcessor();
+        $protocol->useIterableMultibulk(true);
 
         $connection = new ComposableStreamConnection($parameters, $protocol);
 

+ 42 - 41
tests/Predis/Protocol/Text/ComposableTextProtocolTest.php → tests/Predis/Protocol/Text/ComposableProtocolProcessorTest.php

@@ -16,32 +16,61 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class ComposableTextProtocolTest extends StandardTestCase
+class ComposableProtocolProcessorTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
-    public function testCustomSerializer()
+    public function testConstructor()
     {
-        $serializer = $this->getMock('Predis\Protocol\CommandSerializerInterface');
+        $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 ComposableTextProtocol();
-        $protocol->setSerializer($serializer);
+        $protocol = new ComposableProtocolProcessor();
+        $protocol->setRequestSerializer($serializer);
 
-        $this->assertSame($serializer, $protocol->getSerializer());
+        $this->assertSame($serializer, $protocol->getRequestSerializer());
     }
 
     /**
      * @group disconnected
      */
-    public function testCustomReader()
+    public function testCustomResponseReader()
     {
         $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface');
 
-        $protocol = new ComposableTextProtocol();
-        $protocol->setReader($reader);
+        $protocol = new ComposableProtocolProcessor();
+        $protocol->setResponseReader($reader);
 
-        $this->assertSame($reader, $protocol->getReader());
+        $this->assertSame($reader, $protocol->getResponseReader());
     }
 
     /**
@@ -53,10 +82,9 @@ class ComposableTextProtocolTest extends StandardTestCase
 
         $command = $this->getMock('Predis\Command\CommandInterface');
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
-        $serializer = $this->getMock('Predis\Protocol\CommandSerializerInterface');
+        $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface');
 
-        $protocol = new ComposableTextProtocol();
-        $protocol->setSerializer($serializer);
+        $protocol = new ComposableProtocolProcessor($serializer);
 
         $connection->expects($this->once())
                    ->method('writeBytes')
@@ -80,8 +108,7 @@ class ComposableTextProtocolTest extends StandardTestCase
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
         $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface');
 
-        $protocol = new ComposableTextProtocol();
-        $protocol->setReader($reader);
+        $protocol = new ComposableProtocolProcessor(null, $reader);
 
         $reader->expects($this->once())
                    ->method('read')
@@ -90,30 +117,4 @@ class ComposableTextProtocolTest extends StandardTestCase
 
         $this->assertSame('bulk', $protocol->read($connection));
     }
-
-    /**
-     * @group disconnected
-     */
-    public function testSetMultibulkOption()
-    {
-        $protocol = new ComposableTextProtocol();
-        $reader = $protocol->getReader();
-
-        $protocol->setOption('iterable_multibulk', true);
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseMultiBulkStreamHandler', $reader->getHandler('*'));
-
-        $protocol->setOption('iterable_multibulk', false);
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseMultiBulkHandler', $reader->getHandler('*'));
-    }
-
-    /**
-     * @group disconnected
-     * @expectedException InvalidArgumentException
-     * @expectedExceptionMessage The option unknown_option is not supported by the current protocol
-     */
-    public function testSetInvalidOption()
-    {
-        $protocol = new ComposableTextProtocol();
-        $protocol->setOption('unknown_option', true);
-    }
 }

+ 6 - 6
tests/Predis/Protocol/Text/ResponseBulkHandlerTest.php → tests/Predis/Protocol/Text/Handler/BulkResponseTest.php

@@ -16,14 +16,14 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class ResponseBulkHandlerTest extends StandardTestCase
+class BulkResponseTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testZeroLengthBulk()
     {
-        $handler = new ResponseBulkHandler();
+        $handler = new Handler\BulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -44,7 +44,7 @@ class ResponseBulkHandlerTest extends StandardTestCase
         $bulk = "This is a bulk string.";
         $bulkLengh = (string) strlen($bulk);
 
-        $handler = new ResponseBulkHandler();
+        $handler = new Handler\BulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -62,7 +62,7 @@ class ResponseBulkHandlerTest extends StandardTestCase
      */
     public function testNull()
     {
-        $handler = new ResponseBulkHandler();
+        $handler = new Handler\BulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -75,11 +75,11 @@ class ResponseBulkHandlerTest extends StandardTestCase
     /**
      * @group disconnected
      * @expectedException Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as bulk length
+     * @expectedExceptionMessage Cannot parse 'invalid' as the length of the bulk response
      */
     public function testInvalidLength()
     {
-        $handler = new ResponseBulkHandler();
+        $handler = new Handler\BulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 2 - 2
tests/Predis/Protocol/Text/ResponseErrorHandlerTest.php → tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php

@@ -16,14 +16,14 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class ResponseErrorHandlerTest extends StandardTestCase
+class ErrorResponseTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testOk()
     {
-        $handler = new ResponseErrorHandler();
+        $handler = new Handler\ErrorResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 5 - 5
tests/Predis/Protocol/Text/ResponseIntegerHandlerTest.php → tests/Predis/Protocol/Text/Handler/IntegerResponse.php

@@ -17,14 +17,14 @@ use Predis\ResponseQueued;
 /**
  *
  */
-class ResponseIntegerHandlerTest extends StandardTestCase
+class IntegerResponseTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testInteger()
     {
-        $handler = new ResponseIntegerHandler();
+        $handler = new Handler\IntegerResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -42,7 +42,7 @@ class ResponseIntegerHandlerTest extends StandardTestCase
      */
     public function testNull()
     {
-        $handler = new ResponseIntegerHandler();
+        $handler = new Handler\IntegerResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -55,11 +55,11 @@ class ResponseIntegerHandlerTest extends StandardTestCase
     /**
      * @group disconnected
      * @expectedException Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as numeric response
+     * @expectedExceptionMessage Cannot parse 'invalid' as a numeric response
      */
     public function testInvalid()
     {
-        $handler = new ResponseIntegerHandler();
+        $handler = new Handler\IntegerResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 6 - 6
tests/Predis/Protocol/Text/ResponseMultiBulkHandlerTest.php → tests/Predis/Protocol/Text/Handler/MultiBulkResponse.php

@@ -16,20 +16,20 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class ResponseMultiBulkHandlerTest extends StandardTestCase
+class MultiBulkResponseTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testMultiBulk()
     {
-        $handler = new ResponseMultiBulkHandler();
+        $handler = new Handler\MultiBulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
         $connection->expects($this->once())
                    ->method('getProtocol')
-                   ->will($this->returnValue(new ComposableTextProtocol()));
+                   ->will($this->returnValue(new ComposableProtocolProcessor()));
 
         $connection->expects($this->at(1))
                    ->method('readLine')
@@ -55,7 +55,7 @@ class ResponseMultiBulkHandlerTest extends StandardTestCase
      */
     public function testNull()
     {
-        $handler = new ResponseMultiBulkHandler();
+        $handler = new Handler\MultiBulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -68,11 +68,11 @@ class ResponseMultiBulkHandlerTest extends StandardTestCase
     /**
      * @group disconnected
      * @expectedException Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as multi-bulk length
+     * @expectedExceptionMessage Cannot parse 'invalid' as the length of the multibulk response
      */
     public function testInvalid()
     {
-        $handler = new ResponseMultiBulkHandler();
+        $handler = new Handler\MultiBulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 4 - 4
tests/Predis/Protocol/Text/ResponseStatusHandlerTest.php → tests/Predis/Protocol/Text/Handler/StatusResponseTest.php

@@ -17,14 +17,14 @@ use Predis\ResponseQueued;
 /**
  *
  */
-class ResponseStatusHandlerTest extends StandardTestCase
+class StatusResponseTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testOk()
     {
-        $handler = new ResponseStatusHandler();
+        $handler = new Handler\StatusResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -39,7 +39,7 @@ class ResponseStatusHandlerTest extends StandardTestCase
      */
     public function testQueued()
     {
-        $handler = new ResponseStatusHandler();
+        $handler = new Handler\StatusResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -54,7 +54,7 @@ class ResponseStatusHandlerTest extends StandardTestCase
      */
     public function testPlainString()
     {
-        $handler = new ResponseStatusHandler();
+        $handler = new Handler\StatusResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 4 - 4
tests/Predis/Protocol/Text/ResponseMultiBulkStreamHandlerTest.php → tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php

@@ -16,14 +16,14 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class ResponseMultiBulkStreamHandlerTest extends StandardTestCase
+class StreamableMultiBulkResponseTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testOk()
     {
-        $handler = new ResponseMultiBulkStreamHandler();
+        $handler = new Handler\StreamableMultiBulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -36,11 +36,11 @@ class ResponseMultiBulkStreamHandlerTest extends StandardTestCase
     /**
      * @group disconnected
      * @expectedException Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as multi-bulk length
+     * @expectedExceptionMessage Cannot parse 'invalid' as the length of the multibulk response
      */
     public function testInvalid()
     {
-        $handler = new ResponseMultiBulkStreamHandler();
+        $handler = new Handler\StreamableMultiBulkResponse();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 6 - 6
tests/Predis/Protocol/Text/TextProtocolTest.php → tests/Predis/Protocol/Text/ProtocolProcessorTest.php

@@ -16,7 +16,7 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class TextProtocolTest extends StandardTestCase
+class ProtocolProcessorTest extends StandardTestCase
 {
     /**
      * @group disconnected
@@ -24,7 +24,7 @@ class TextProtocolTest extends StandardTestCase
     public function testConnectionWrite()
     {
         $serialized = "*1\r\n$4\r\nPING\r\n";
-        $protocol = new TextProtocol();
+        $protocol = new ProtocolProcessor();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
 
@@ -52,7 +52,7 @@ class TextProtocolTest extends StandardTestCase
      */
     public function testConnectionRead()
     {
-        $protocol = new TextProtocol();
+        $protocol = new ProtocolProcessor();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -88,8 +88,8 @@ class TextProtocolTest extends StandardTestCase
      */
     public function testIterableMultibulkSupport()
     {
-        $protocol = new TextProtocol();
-        $protocol->setOption('iterable_multibulk', true);
+        $protocol = new ProtocolProcessor();
+        $protocol->useIterableMultibulk(true);
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -107,7 +107,7 @@ class TextProtocolTest extends StandardTestCase
      */
     public function testUnknownResponsePrefix()
     {
-        $protocol = new TextProtocol();
+        $protocol = new ProtocolProcessor();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 

+ 3 - 3
tests/Predis/Protocol/Text/TextCommandSerializerTest.php → tests/Predis/Protocol/Text/RequestSerializerTest.php

@@ -16,14 +16,14 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class TextCommandSerializerTest extends StandardTestCase
+class RequestSerializerTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testSerializerIdWithNoArguments()
     {
-        $serializer = new TextCommandSerializer();
+        $serializer = new RequestSerializer();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
 
@@ -45,7 +45,7 @@ class TextCommandSerializerTest extends StandardTestCase
      */
     public function testSerializerIdWithArguments()
     {
-        $serializer = new TextCommandSerializer();
+        $serializer = new RequestSerializer();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
 

+ 14 - 14
tests/Predis/Protocol/Text/TextResponseReaderTest.php → tests/Predis/Protocol/Text/ResponseReaderTest.php

@@ -16,20 +16,20 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
 /**
  *
  */
-class TextResponseReaderTest extends StandardTestCase
+class ResponseReaderTest extends StandardTestCase
 {
     /**
      * @group disconnected
      */
     public function testDefaultHandlers()
     {
-        $reader = new TextResponseReader();
+        $reader = new ResponseReader();
 
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseStatusHandler', $reader->getHandler('+'));
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseErrorHandler', $reader->getHandler('-'));
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseIntegerHandler', $reader->getHandler(':'));
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseBulkHandler', $reader->getHandler('$'));
-        $this->assertInstanceOf('Predis\Protocol\Text\ResponseMultiBulkHandler', $reader->getHandler('*'));
+        $this->assertInstanceOf('Predis\Protocol\Text\Handler\StatusResponse', $reader->getHandler('+'));
+        $this->assertInstanceOf('Predis\Protocol\Text\Handler\ErrorResponse', $reader->getHandler('-'));
+        $this->assertInstanceOf('Predis\Protocol\Text\Handler\IntegerResponse', $reader->getHandler(':'));
+        $this->assertInstanceOf('Predis\Protocol\Text\Handler\BulkResponse', $reader->getHandler('$'));
+        $this->assertInstanceOf('Predis\Protocol\Text\Handler\MultiBulkResponse', $reader->getHandler('*'));
 
         $this->assertNull($reader->getHandler('!'));
     }
@@ -39,9 +39,9 @@ class TextResponseReaderTest extends StandardTestCase
      */
     public function testReplaceHandler()
     {
-        $handler = $this->getMock('Predis\Protocol\ResponseHandlerInterface');
+        $handler = $this->getMock('Predis\Protocol\Text\Handler\ResponseHandlerInterface');
 
-        $reader = new TextResponseReader();
+        $reader = new ResponseReader();
         $reader->setHandler('+', $handler);
 
         $this->assertSame($handler, $reader->getHandler('+'));
@@ -52,10 +52,10 @@ class TextResponseReaderTest extends StandardTestCase
      */
     public function testReadResponse()
     {
-        $reader = new TextResponseReader();
+        $reader = new ResponseReader();
 
-        $protocol = new ComposableTextProtocol();
-        $protocol->setReader($reader);
+        $protocol = new ComposableProtocolProcessor();
+        $protocol->setResponseReader($reader);
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -93,7 +93,7 @@ class TextResponseReaderTest extends StandardTestCase
      */
     public function testEmptyResponseHeader()
     {
-        $reader = new TextResponseReader();
+        $reader = new ResponseReader();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');
 
@@ -110,7 +110,7 @@ class TextResponseReaderTest extends StandardTestCase
      */
     public function testUnknownResponsePrefix()
     {
-        $reader = new TextResponseReader();
+        $reader = new ResponseReader();
 
         $connection = $this->getMock('Predis\Connection\ComposableConnectionInterface');