Browse Source

Get string of basic connection parameters from parameters class.

Daniele Alessandri 8 năm trước cách đây
mục cha
commit
8b466d05df

+ 2 - 1
src/CommunicationException.php

@@ -34,8 +34,9 @@ abstract class CommunicationException extends PredisException
         $code = null,
         \Exception $innerException = null
     ) {
-        parent::__construct($message, $code, $innerException);
         $this->connection = $connection;
+
+        parent::__construct($message, $code, $innerException);
     }
 
     /**

+ 2 - 25
src/Connection/AbstractConnection.php

@@ -120,29 +120,6 @@ abstract class AbstractConnection implements NodeConnectionInterface
         return $this->read();
     }
 
-    /**
-     * Helper method that returns an exception message augmented with useful
-     * details from the connection parameters.
-     *
-     * @param string $message Error message.
-     *
-     * @return string
-     */
-    private function createExceptionMessage($message)
-    {
-        $parameters = $this->parameters;
-
-        if ($parameters->scheme === 'unix') {
-            return "$message [$parameters->scheme:$parameters->path]";
-        }
-
-        if (filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
-            return "$message [$parameters->scheme://[$parameters->host]:$parameters->port]";
-        }
-
-        return "$message [$parameters->scheme://$parameters->host:$parameters->port]";
-    }
-
     /**
      * Helper method to handle connection errors.
      *
@@ -152,7 +129,7 @@ abstract class AbstractConnection implements NodeConnectionInterface
     protected function onConnectionError($message, $code = null)
     {
         CommunicationException::handle(
-            new ConnectionException($this, static::createExceptionMessage($message), $code)
+            new ConnectionException($this, "$message [{$this->getParameters()}]", $code)
         );
     }
 
@@ -164,7 +141,7 @@ abstract class AbstractConnection implements NodeConnectionInterface
     protected function onProtocolError($message)
     {
         CommunicationException::handle(
-            new ProtocolException($this, static::createExceptionMessage($message))
+            new ProtocolException($this, "$message [{$this->getParameters()}]")
         );
     }
 

+ 18 - 2
src/Connection/Parameters.php

@@ -128,6 +128,14 @@ class Parameters implements ParametersInterface
         return $parsed;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        return $this->parameters;
+    }
+
     /**
      * Validates and converts each value of the connection parameters array.
      *
@@ -161,9 +169,17 @@ class Parameters implements ParametersInterface
     /**
      * {@inheritdoc}
      */
-    public function toArray()
+    public function __toString()
     {
-        return $this->parameters;
+        if ($this->scheme === 'unix') {
+            return "$this->scheme:$this->path";
+        }
+
+        if (filter_var($this->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
+            return "$this->scheme://[$this->host]:$this->port";
+        }
+
+        return "$this->scheme://$this->host:$this->port";
     }
 
     /**

+ 7 - 0
src/Connection/ParametersInterface.php

@@ -53,6 +53,13 @@ interface ParametersInterface
      */
     public function __get($parameter);
 
+    /**
+     * Returns basic connection parameters as a valid URI string.
+     *
+     * @return string
+     */
+    public function __toString();
+
     /**
      * Returns an array representation of the connection parameters.
      *

+ 2 - 2
src/Connection/WebdisConnection.php

@@ -280,10 +280,10 @@ class WebdisConnection implements NodeConnectionInterface
         curl_setopt($resource, CURLOPT_POSTFIELDS, $serializedCommand);
 
         if (curl_exec($resource) === false) {
-            $error = curl_error($resource);
+            $error = trim(curl_error($resource));
             $errno = curl_errno($resource);
 
-            throw new ConnectionException($this, trim($error), $errno);
+            throw new ConnectionException($this, "$error{$this->getParameters()}]", $errno);
         }
 
         if (phpiredis_reader_get_state($this->reader) !== PHPIREDIS_READER_STATE_COMPLETE) {

+ 2 - 2
src/Protocol/Text/Handler/BulkResponse.php

@@ -34,7 +34,7 @@ class BulkResponse implements ResponseHandlerInterface
 
         if ("$length" !== $payload) {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$payload' as a valid length for a bulk response."
+                $connection, "Cannot parse '$payload' as a valid length for a bulk response [{$connection->getParameters()}]"
             ));
         }
 
@@ -47,7 +47,7 @@ class BulkResponse implements ResponseHandlerInterface
         }
 
         CommunicationException::handle(new ProtocolException(
-            $connection, "Value '$payload' is not a valid length for a bulk response."
+            $connection, "Value '$payload' is not a valid length for a bulk response [{$connection->getParameters()}]"
         ));
 
         return;

+ 1 - 1
src/Protocol/Text/Handler/IntegerResponse.php

@@ -38,7 +38,7 @@ class IntegerResponse implements ResponseHandlerInterface
 
         if ($payload !== 'nil') {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$payload' as a valid numeric response."
+                $connection, "Cannot parse '$payload' as a valid numeric response [{$connection->getParameters()}]"
             ));
         }
 

+ 1 - 1
src/Protocol/Text/Handler/MultiBulkResponse.php

@@ -34,7 +34,7 @@ class MultiBulkResponse implements ResponseHandlerInterface
 
         if ("$length" !== $payload) {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$payload' as a valid length of a multi-bulk response."
+                $connection, "Cannot parse '$payload' as a valid length of a multi-bulk response [{$connection->getParameters()}]"
             ));
         }
 

+ 1 - 1
src/Protocol/Text/Handler/StreamableMultiBulkResponse.php

@@ -38,7 +38,7 @@ class StreamableMultiBulkResponse implements ResponseHandlerInterface
 
         if ("$length" != $payload) {
             CommunicationException::handle(new ProtocolException(
-                $connection, "Cannot parse '$payload' as a valid length for a multi-bulk response."
+                $connection, "Cannot parse '$payload' as a valid length for a multi-bulk response [{$connection->getParameters()}]"
             ));
         }
 

+ 1 - 1
src/Protocol/Text/ProtocolProcessor.php

@@ -99,7 +99,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface
 
             default:
                 CommunicationException::handle(new ProtocolException(
-                    $connection, "Unknown response prefix: '$prefix'."
+                    $connection, "Unknown response prefix: '$prefix' [{$connection->getParameters()}]"
                 ));
 
                 return;

+ 3 - 3
src/Protocol/Text/ResponseReader.php

@@ -86,13 +86,13 @@ class ResponseReader implements ResponseReaderInterface
         $header = $connection->readLine();
 
         if ($header === '') {
-            $this->onProtocolError($connection, 'Unexpected empty reponse header.');
+            $this->onProtocolError($connection, 'Unexpected empty reponse header');
         }
 
         $prefix = $header[0];
 
         if (!isset($this->handlers[$prefix])) {
-            $this->onProtocolError($connection, "Unknown response prefix: '$prefix'.");
+            $this->onProtocolError($connection, "Unknown response prefix: '$prefix'");
         }
 
         $payload = $this->handlers[$prefix]->handle($connection, substr($header, 1));
@@ -110,7 +110,7 @@ class ResponseReader implements ResponseReaderInterface
     protected function onProtocolError(CompositeConnectionInterface $connection, $message)
     {
         CommunicationException::handle(
-            new ProtocolException($connection, $message)
+            new ProtocolException($connection, "$message [{$connection->getParameters()}]")
         );
     }
 }

+ 18 - 5
tests/PHPUnit/PredisTestCase.php

@@ -187,15 +187,16 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface.
+     * Returns a basic mocked connection of the specified type.
      *
-     * @param mixed $parameters Optional parameters.
+     * @param string $interface  Connection type.
+     * @param mixed  $parameters Optional parameters.
      *
-     * @return mixed
+     * @return \Predis\Connection\NodeConnectionInterface
      */
-    protected function getMockConnection($parameters = null)
+    protected function getMockConnectionOfType($interface, $parameters = null)
     {
-        $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
+        $connection = $this->getMock($interface);
 
         if ($parameters) {
             $parameters = Connection\Parameters::create($parameters);
@@ -212,6 +213,18 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
         return $connection;
     }
 
+    /**
+     * Returns a basic mocked connection of type Predis\Connection\NodeConnectionInterface.
+     *
+     * @param mixed $parameters Optional parameters.
+     *
+     * @return \Predis\Connection\NodeConnectionInterface
+     */
+    protected function getMockConnection($parameters = null)
+    {
+        return $this->getMockConnectionOfType('Predis\Connection\NodeConnectionInterface', $parameters);
+    }
+
     /**
      * Returns the server version of the Redis instance used by the test suite.
      *

+ 52 - 42
tests/Predis/CommunicationExceptionTest.php

@@ -21,35 +21,34 @@ class CommunicationExceptionTest extends PredisTestCase
     /**
      * @group disconnected
      */
-    public function testExceptionMessage()
+    public function testExceptionReturnsInnerConnection()
     {
-        $message = 'Connection error message.';
-        $connection = $this->getMockedConnectionBase();
-        $exception = $this->getException($connection, $message);
-
-        $this->setExpectedException('Predis\CommunicationException', $message);
+        $connection = $this->getMockConnection();
+        $exception = $this->createMockException($connection, 'Communication error message');
 
-        throw $exception;
+        $this->assertSame($connection, $exception->getConnection());
     }
 
     /**
      * @group disconnected
+     * @expectedException \Predis\CommunicationException
+     * @expectedExceptionMessage Connection error message
      */
-    public function testExceptionConnection()
+    public function testExceptionMessage()
     {
-        $connection = $this->getMockedConnectionBase();
-        $exception = $this->getException($connection, 'ERROR MESSAGE');
+        $connection = $this->getMockConnection();
+        $exception = $this->createMockException($connection, 'Connection error message');
 
-        $this->assertSame($connection, $exception->getConnection());
+        throw $exception;
     }
 
     /**
      * @group disconnected
      */
-    public function testShouldResetConnection()
+    public function testShouldResetConnectionIsTrue()
     {
-        $connection = $this->getMockedConnectionBase();
-        $exception = $this->getException($connection, 'ERROR MESSAGE');
+        $connection = $this->getMockConnection();
+        $exception = $this->createMockException($connection, 'Communication error message');
 
         $this->assertTrue($exception->shouldResetConnection());
     }
@@ -57,43 +56,55 @@ class CommunicationExceptionTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\CommunicationException
-     * @expectedExceptionMessage Communication error
+     * @expectedExceptionMessage Communication error message
      */
     public function testCommunicationExceptionHandling()
     {
-        $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true));
-        $connection->expects($this->once())->method('disconnect');
+        $connection = $this->getMockConnection();
+        $connection
+            ->expects($this->once())
+            ->method('isConnected')
+            ->will($this->returnValue(true));
+        $connection
+            ->expects($this->once())
+            ->method('disconnect');
 
-        $exception = $this->getException($connection, 'Communication error');
+        $exception = $this->createMockException($connection, 'Communication error message');
 
         CommunicationException::handle($exception);
     }
 
-    // ******************************************************************** //
-    // ---- HELPER METHODS ------------------------------------------------ //
-    // ******************************************************************** //
-
     /**
-     * Returns a mocked connection instance.
-     *
-     * @param mixed $parameters Connection parameters.
-     *
-     * @return Connection\NodeConnectionInterface
+     * @group disconnected
+     * @expectedException \Predis\CommunicationException
+     * @expectedExceptionMessage Communication error message
      */
-    protected function getMockedConnectionBase($parameters = null)
+    public function testCommunicationExceptionHandlingWhenShouldResetConnectionIsFalse()
     {
-        $builder = $this->getMockBuilder('Predis\Connection\AbstractConnection');
-
-        if ($parameters === null) {
-            $builder->disableOriginalConstructor();
-        } elseif (!$parameters instanceof Connection\ParametersInterface) {
-            $parameters = new Connection\Parameters($parameters);
-        }
+        $connection = $this->getMockConnection();
+        $connection
+            ->expects($this->never())
+            ->method('isConnected');
+        $connection
+            ->expects($this->never())
+            ->method('disconnect');
+
+        $exception = $this->getMockBuilder('Predis\CommunicationException')
+            ->setConstructorArgs(array($connection, 'Communication error message'))
+            ->setMethods(array('shouldResetConnection'))
+            ->getMockForAbstractClass();
+        $exception
+            ->expects($this->once())
+            ->method('shouldResetConnection')
+            ->will($this->returnValue(false));
 
-        return $builder->getMockForAbstractClass(array($parameters));
+        CommunicationException::handle($exception);
     }
 
+    // ******************************************************************** //
+    // ---- HELPER METHODS ------------------------------------------------ //
+    // ******************************************************************** //
+
     /**
      * Returns a connection exception instance.
      *
@@ -104,15 +115,14 @@ class CommunicationExceptionTest extends PredisTestCase
      *
      * @return \Predis\CommunicationException
      */
-    protected function getException(
+    protected function createMockException(
         Connection\NodeConnectionInterface $connection,
         $message,
         $code = 0,
         \Exception $inner = null
     ) {
-        $arguments = array($connection, $message, $code, $inner);
-        $mock = $this->getMockForAbstractClass('Predis\CommunicationException', $arguments);
-
-        return $mock;
+        return $this->getMockBuilder('Predis\CommunicationException')
+            ->setConstructorArgs(array($connection, $message, $code, $inner))
+            ->getMockForAbstractClass();
     }
 }

+ 43 - 0
tests/Predis/Connection/ParametersTest.php

@@ -316,6 +316,49 @@ class ParametersTest extends PredisTestCase
         Parameters::parse('tcp://invalid:uri');
     }
 
+    /**
+     * @group disconnected
+     */
+    public function testToStringWithDefaultParameters()
+    {
+        $parameters = new Parameters();
+
+        $this->assertSame('tcp://127.0.0.1:6379', (string) $parameters);
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testToStringWithUnixScheme()
+    {
+        $uri = 'unix:/path/to/redis.sock';
+        $parameters = Parameters::create("$uri?foo=bar");
+
+        $this->assertSame($uri, (string) $parameters);
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testToStringWithIPv4()
+    {
+        $uri = 'tcp://127.0.0.1:6379';
+        $parameters = Parameters::create("$uri?foo=bar");
+
+        $this->assertSame($uri, (string) $parameters);
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testToStringWithIPv6()
+    {
+        $uri = 'tcp://[::1]:6379';
+        $parameters = Parameters::create("$uri?foo=bar");
+
+        $this->assertSame($uri, (string) $parameters);
+    }
+
     // ******************************************************************** //
     // ---- HELPER METHODS ------------------------------------------------ //
     // ******************************************************************** //

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

@@ -25,7 +25,7 @@ class BulkResponseTest extends PredisTestCase
     {
         $handler = new Handler\BulkResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->once())
@@ -46,7 +46,7 @@ class BulkResponseTest extends PredisTestCase
 
         $handler = new Handler\BulkResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->once())
@@ -64,7 +64,7 @@ class BulkResponseTest extends PredisTestCase
     {
         $handler = new Handler\BulkResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->never())->method('readBuffer');
@@ -75,17 +75,34 @@ class BulkResponseTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a bulk response.
+     * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a bulk response [tcp://127.0.0.1:6379]
      */
-    public function testInvalidLength()
+    public function testInvalidLengthString()
     {
         $handler = new Handler\BulkResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->never())->method('readBuffer');
 
         $handler->handle($connection, 'invalid');
     }
+
+    /**
+     * @group disconnected
+     * @expectedException \Predis\Protocol\ProtocolException
+     * @expectedExceptionMessage Value '-5' is not a valid length for a bulk response [tcp://127.0.0.1:6379]
+     */
+    public function testInvalidLengthInteger()
+    {
+        $handler = new Handler\BulkResponse();
+
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+
+        $connection->expects($this->never())->method('readLine');
+        $connection->expects($this->never())->method('readBuffer');
+
+        $handler->handle($connection, '-5');
+    }
 }

+ 2 - 2
tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php

@@ -54,13 +54,13 @@ class IntegerResponseTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as a valid numeric response.
+     * @expectedExceptionMessage Cannot parse 'invalid' as a valid numeric response [tcp://127.0.0.1:6379]
      */
     public function testInvalid()
     {
         $handler = new Handler\IntegerResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->never())->method('readBuffer');

+ 2 - 2
tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php

@@ -68,13 +68,13 @@ class MultiBulkResponseTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as a valid length of a multi-bulk response.
+     * @expectedExceptionMessage Cannot parse 'invalid' as a valid length of a multi-bulk response [tcp://127.0.0.1:6379]
      */
     public function testInvalid()
     {
         $handler = new Handler\MultiBulkResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->never())->method('readBuffer');

+ 2 - 2
tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php

@@ -36,13 +36,13 @@ class StreamableMultiBulkResponseTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a multi-bulk response.
+     * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a multi-bulk response [tcp://127.0.0.1:6379]
      */
     public function testInvalid()
     {
         $handler = new Handler\StreamableMultiBulkResponse();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->never())->method('readLine');
         $connection->expects($this->never())->method('readBuffer');

+ 5 - 5
tests/Predis/Protocol/Text/ProtocolProcessorTest.php

@@ -36,7 +36,7 @@ class ProtocolProcessorTest extends PredisTestCase
                 ->method('getArguments')
                 ->will($this->returnValue(array()));
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->once())
                    ->method('writeBuffer')
@@ -52,7 +52,7 @@ class ProtocolProcessorTest extends PredisTestCase
     {
         $protocol = new ProtocolProcessor();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->at(0))
                    ->method('readLine')
@@ -89,7 +89,7 @@ class ProtocolProcessorTest extends PredisTestCase
         $protocol = new ProtocolProcessor();
         $protocol->useIterableMultibulk(true);
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->once(4))
                    ->method('readLine')
@@ -101,13 +101,13 @@ class ProtocolProcessorTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Unknown response prefix: '!'.
+     * @expectedExceptionMessage Unknown response prefix: '!' [tcp://127.0.0.1:6379]
      */
     public function testUnknownResponsePrefix()
     {
         $protocol = new ProtocolProcessor();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->once())
                    ->method('readLine')

+ 5 - 5
tests/Predis/Protocol/Text/ResponseReaderTest.php

@@ -57,7 +57,7 @@ class ResponseReaderTest extends PredisTestCase
         $protocol = new CompositeProtocolProcessor();
         $protocol->setResponseReader($reader);
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
 
         $connection->expects($this->at(0))
                    ->method('readLine')
@@ -89,13 +89,13 @@ class ResponseReaderTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Unexpected empty reponse header.
+     * @expectedExceptionMessage Unexpected empty reponse header [tcp://127.0.0.1:6379]
      */
     public function testEmptyResponseHeader()
     {
         $reader = new ResponseReader();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->once())
                    ->method('readLine')
@@ -106,13 +106,13 @@ class ResponseReaderTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException \Predis\Protocol\ProtocolException
-     * @expectedExceptionMessage Unknown response prefix: '!'.
+     * @expectedExceptionMessage Unknown response prefix: '!' [tcp://127.0.0.1:6379]
      */
     public function testUnknownResponsePrefix()
     {
         $reader = new ResponseReader();
 
-        $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
 
         $connection->expects($this->once())
                    ->method('readLine')