From d1d2b3b3545dfae139cec69aa1d93de4676f6beb Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 14:55:01 +0000 Subject: [PATCH] Test for 'false' database value when not found in DSN --- lib/Resque/Redis.php | 5 +++-- test/Resque/Tests/DsnTest.php | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 41fec07..be5492a 100755 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -109,7 +109,8 @@ class Resque_Redis /** * @param string|array $server A DSN or array - * @param int $database A database number to select + * @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. */ public function __construct($server, $database = null) { @@ -134,7 +135,7 @@ class Resque_Redis } // If we have found a database in our DSN, use it instead of the `$database` - // value passed into the constructor + // value passed into the constructor. if ($dsnDatabase !== false) { $database = $dsnDatabase; $this->database = $database; diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php index 2fc6654..7e483a3 100755 --- a/test/Resque/Tests/DsnTest.php +++ b/test/Resque/Tests/DsnTest.php @@ -21,21 +21,21 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('', array( 'localhost', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('localhost', array( 'localhost', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('localhost:1234', array( 'localhost', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), @@ -49,14 +49,14 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('redis://foobar', array( 'foobar', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('redis://foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), @@ -67,10 +67,17 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase false, false, array(), )), + array('redis://foobar:1234/0', array( + 'foobar', + 1234, + 0, + false, false, + array(), + )), array('redis://user@foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', false, array(), )), @@ -84,35 +91,35 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('redis://user:pass@foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', 'pass', array(), )), array('redis://user:pass@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', 'pass', array('x' => 'y', 'a' => 'b'), )), array('redis://:pass@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, 'pass', array('x' => 'y', 'a' => 'b'), )), array('redis://user@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', false, array('x' => 'y', 'a' => 'b'), )), array('redis://foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array('x' => 'y', 'a' => 'b'), )),