From d55826f35cbce2e1125d91500ccfa00ee1a82a8d Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Tue, 17 May 2016 20:06:30 +0200 Subject: [PATCH] [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. --- .../CompositeStreamConnectionTest.php | 29 +++++++++++++++++++ .../PhpiredisSocketConnectionTest.php | 1 - .../PhpiredisStreamConnectionTest.php | 1 - .../Connection/StreamConnectionTest.php | 1 - 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/Predis/Connection/CompositeStreamConnectionTest.php b/tests/Predis/Connection/CompositeStreamConnectionTest.php index 20cbad40..62f3983c 100644 --- a/tests/Predis/Connection/CompositeStreamConnectionTest.php +++ b/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 --------------------------------------------- // // ******************************************************************** // diff --git a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php index a2b5d9db..3ccb4663 100644 --- a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php +++ b/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')) diff --git a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php index 6e453b76..85d6fb63 100644 --- a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php +++ b/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')) diff --git a/tests/Predis/Connection/StreamConnectionTest.php b/tests/Predis/Connection/StreamConnectionTest.php index a21fc24a..5398c7c8 100644 --- a/tests/Predis/Connection/StreamConnectionTest.php +++ b/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'))