mirror of
https://github.com/predis/predis.git
synced 2026-10-19 02:06:08 +00:00
Change how Redis errors such as -ERR replies generates exceptions.
The "throw_errors" connection parameter has been removed and replaced by the new "exceptions" client option since exceptions on -ERR replies returned by Redis are not generated by connection classes anymore but are thrown by the client class and other abstractions such as pipeline contexts. This change does not affect much people using the Predis\Client class (aside from the different configuration) but gives much more flexibility to those building their own pieces of code around the internal classes of Predis.
This commit is contained in:
@@ -321,6 +321,44 @@ class ClientTest extends StandardTestCase
|
||||
$this->assertTrue($client->executeCommand($ping));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @expectedException Predis\ServerException
|
||||
* @expectedExceptionMessage ERR Operation against a key holding the wrong kind of value
|
||||
*/
|
||||
public function testExecuteCommandThrowsExceptionOnRedisError()
|
||||
{
|
||||
$ping = ServerProfile::getDefault()->createCommand('ping', array());
|
||||
$expectedResponse = new ResponseError('ERR Operation against a key holding the wrong kind of value');
|
||||
|
||||
$connection= $this->getMock('Predis\Connection\ConnectionInterface');
|
||||
$connection->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->will($this->returnValue($expectedResponse));
|
||||
|
||||
$client = new Client($connection);
|
||||
$client->executeCommand($ping);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testExecuteCommandReturnsErrorResponseOnRedisError()
|
||||
{
|
||||
$ping = ServerProfile::getDefault()->createCommand('ping', array());
|
||||
$expectedResponse = new ResponseError('ERR Operation against a key holding the wrong kind of value');
|
||||
|
||||
$connection= $this->getMock('Predis\Connection\ConnectionInterface');
|
||||
$connection->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->will($this->returnValue($expectedResponse));
|
||||
|
||||
$client = new Client($connection, array('exceptions' => false));
|
||||
$response = $client->executeCommand($ping);
|
||||
|
||||
$this->assertSame($response, $expectedResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
@@ -345,6 +383,44 @@ class ClientTest extends StandardTestCase
|
||||
$this->assertTrue($client->ping());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @expectedException Predis\ServerException
|
||||
* @expectedExceptionMessage ERR Operation against a key holding the wrong kind of value
|
||||
*/
|
||||
public function testCallingRedisCommandThrowsExceptionOnServerError()
|
||||
{
|
||||
$expectedResponse = new ResponseError('ERR Operation against a key holding the wrong kind of value');
|
||||
|
||||
$connection = $this->getMock('Predis\Connection\ConnectionInterface');
|
||||
$connection->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isInstanceOf('Predis\Command\ConnectionPing'))
|
||||
->will($this->returnValue($expectedResponse));
|
||||
|
||||
$client = new Client($connection);
|
||||
$client->ping();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testCallingRedisCommandReturnsErrorResponseOnRedisError()
|
||||
{
|
||||
$expectedResponse = new ResponseError('ERR Operation against a key holding the wrong kind of value');
|
||||
|
||||
$connection = $this->getMock('Predis\Connection\ConnectionInterface');
|
||||
$connection->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->isInstanceOf('Predis\Command\ConnectionPing'))
|
||||
->will($this->returnValue($expectedResponse));
|
||||
|
||||
$client = new Client($connection, array('exceptions' => false));
|
||||
$response = $client->ping();
|
||||
|
||||
$this->assertSame($response, $expectedResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @expectedException Predis\ClientException
|
||||
|
||||
Reference in New Issue
Block a user