Throw when command sent in connect() returns error.

Common failures are the use of SELECT with a database index outside
the bound of the configured number of databases in redis.conf or the
use of a wrong password for authentication with AUTH.

This resolves #322.
This commit is contained in:
Daniele Alessandri
2016-05-17 16:56:34 +02:00
parent f696ed125e
commit 973e8592e3
5 changed files with 102 additions and 2 deletions
@@ -11,6 +11,9 @@
namespace Predis\Connection;
use Predis\Command\RawCommand;
use Predis\Response\Error as ErrorResponse;
/**
*
*/
@@ -18,6 +21,33 @@ class StreamConnectionTest extends PredisConnectionTestCase
{
const CONNECTION_CLASS = 'Predis\Connection\StreamConnection';
/**
* @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');
$responseError =
$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 --------------------------------------------- //
// ******************************************************************** //