mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 08:15:14 +00:00
use a mock to test correct redis exceptions are surfaced
This commit is contained in:
parent
599dc4c8be
commit
8113e624c4
@ -108,13 +108,17 @@ class Resque_Redis
|
|||||||
* @param string|array $server A DSN or array
|
* @param string|array $server A DSN or array
|
||||||
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
|
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
|
||||||
* DSN-supplied value will be used instead and this parameter is ignored.
|
* DSN-supplied value will be used instead and this parameter is ignored.
|
||||||
|
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
|
||||||
*/
|
*/
|
||||||
public function __construct($server, $database = null)
|
public function __construct($server, $database = null, $client = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (is_array($server)) {
|
if (is_array($server)) {
|
||||||
$this->driver = new Credis_Cluster($server);
|
$this->driver = new Credis_Cluster($server);
|
||||||
}
|
}
|
||||||
|
else if (is_object($client)) {
|
||||||
|
$this->driver = $client;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
||||||
// $user is not used, only $password
|
// $user is not used, only $password
|
||||||
|
@ -31,7 +31,15 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRedisErrorThrowsExceptionOnJobCreation()
|
public function testRedisErrorThrowsExceptionOnJobCreation()
|
||||||
{
|
{
|
||||||
Resque::setBackend('redis://255.255.255.255:1234');
|
$mockCredis = $this->getMockBuilder('Credis_Client')
|
||||||
|
->setMethods(['connect', '__call'])
|
||||||
|
->getMock();
|
||||||
|
$mockCredis->expects($this->any())->method('__call')
|
||||||
|
->will($this->throwException(new CredisException('failure')));
|
||||||
|
|
||||||
|
Resque::setBackend(function($database) use ($mockCredis) {
|
||||||
|
return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||||
|
});
|
||||||
Resque::enqueue('jobs', 'This is a test');
|
Resque::enqueue('jobs', 'This is a test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,16 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRedisExceptionsAreSurfaced()
|
public function testRedisExceptionsAreSurfaced()
|
||||||
{
|
{
|
||||||
$redis = new Resque_Redis('redis://255.255.255.255:1234');
|
$mockCredis = $this->getMockBuilder('Credis_Client')
|
||||||
$redis->ping();
|
->setMethods(['connect', '__call'])
|
||||||
|
->getMock();
|
||||||
|
$mockCredis->expects($this->any())->method('__call')
|
||||||
|
->will($this->throwException(new CredisException('failure')));
|
||||||
|
|
||||||
|
Resque::setBackend(function($database) use ($mockCredis) {
|
||||||
|
return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||||
|
});
|
||||||
|
Resque::redis()->ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user