소스 검색

[tests] Fix tests from previous commit.

They did work, but I am not exactly sure why. Also added a missing
test for Predis\Connection\CompositeStreamConnection.
Daniele Alessandri 8 년 전
부모
커밋
d55826f35c

+ 29 - 0
tests/Predis/Connection/CompositeStreamConnectionTest.php

@@ -11,6 +11,9 @@
 
 namespace Predis\Connection;
 
+use Predis\Command\RawCommand;
+use Predis\Response\Error as ErrorResponse;
+
 /**
  *
  */
@@ -18,6 +21,32 @@ class CompositeStreamConnectionTest extends PredisConnectionTestCase
 {
     const CONNECTION_CLASS = 'Predis\Connection\CompositeStreamConnection';
 
+    /**
+     * @group disconnected
+     * @expectedException \Predis\Connection\ConnectionException
+     * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]
+     */
+    public function testThrowsExceptionOnInitializationCommandFailure()
+    {
+        $cmdSelect = RawCommand::create('SELECT', '1000');
+
+        $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
+                           ->setMethods(array('executeCommand', 'createResource'))
+                           ->setConstructorArgs(array(new Parameters()))
+                           ->getMock();
+
+        $connection->method('executeCommand')
+                   ->with($cmdSelect)
+                   ->will($this->returnValue(
+                       new ErrorResponse("ERR invalid DB index")
+                   ));
+
+        $connection->method('createResource');
+
+        $connection->addConnectCommand($cmdSelect);
+        $connection->connect();
+    }
+
     // ******************************************************************** //
     // ---- INTEGRATION TESTS --------------------------------------------- //
     // ******************************************************************** //

+ 0 - 1
tests/Predis/Connection/PhpiredisSocketConnectionTest.php

@@ -54,7 +54,6 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase
     public function testThrowsExceptionOnInitializationCommandFailure()
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
-        $responseError =
 
         $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
                            ->setMethods(array('executeCommand', 'createResource'))

+ 0 - 1
tests/Predis/Connection/PhpiredisStreamConnectionTest.php

@@ -54,7 +54,6 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase
     public function testThrowsExceptionOnInitializationCommandFailure()
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
-        $responseError =
 
         $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
                            ->setMethods(array('executeCommand', 'createResource'))

+ 0 - 1
tests/Predis/Connection/StreamConnectionTest.php

@@ -29,7 +29,6 @@ class StreamConnectionTest extends PredisConnectionTestCase
     public function testThrowsExceptionOnInitializationCommandFailure()
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
-        $responseError =
 
         $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
                            ->setMethods(array('executeCommand', 'createResource'))