Skip to content

Commit d1d2b3b

Browse files
author
Iskandar Najmuddin
committed
Test for 'false' database value when not found in DSN
1 parent 1abbad3 commit d1d2b3b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

lib/Resque/Redis.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public static function prefix($namespace)
109109

110110
/**
111111
* @param string|array $server A DSN or array
112-
* @param int $database A database number to select
112+
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
113+
* DSN-supplied value will be used instead and this parameter is ignored.
113114
*/
114115
public function __construct($server, $database = null)
115116
{
@@ -134,7 +135,7 @@ public function __construct($server, $database = null)
134135
}
135136

136137
// If we have found a database in our DSN, use it instead of the `$database`
137-
// value passed into the constructor
138+
// value passed into the constructor.
138139
if ($dsnDatabase !== false) {
139140
$database = $dsnDatabase;
140141
$this->database = $database;

test/Resque/Tests/DsnTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ public function validDsnStringProvider()
2121
array('', array(
2222
'localhost',
2323
Resque_Redis::DEFAULT_PORT,
24-
Resque_Redis::DEFAULT_DATABASE,
24+
false,
2525
false, false,
2626
array(),
2727
)),
2828
array('localhost', array(
2929
'localhost',
3030
Resque_Redis::DEFAULT_PORT,
31-
Resque_Redis::DEFAULT_DATABASE,
31+
false,
3232
false, false,
3333
array(),
3434
)),
3535
array('localhost:1234', array(
3636
'localhost',
3737
1234,
38-
Resque_Redis::DEFAULT_DATABASE,
38+
false,
3939
false, false,
4040
array(),
4141
)),
@@ -49,14 +49,14 @@ public function validDsnStringProvider()
4949
array('redis://foobar', array(
5050
'foobar',
5151
Resque_Redis::DEFAULT_PORT,
52-
Resque_Redis::DEFAULT_DATABASE,
52+
false,
5353
false, false,
5454
array(),
5555
)),
5656
array('redis://foobar:1234', array(
5757
'foobar',
5858
1234,
59-
Resque_Redis::DEFAULT_DATABASE,
59+
false,
6060
false, false,
6161
array(),
6262
)),
@@ -67,10 +67,17 @@ public function validDsnStringProvider()
6767
false, false,
6868
array(),
6969
)),
70+
array('redis://foobar:1234/0', array(
71+
'foobar',
72+
1234,
73+
0,
74+
false, false,
75+
array(),
76+
)),
7077
array('redis://user@foobar:1234', array(
7178
'foobar',
7279
1234,
73-
Resque_Redis::DEFAULT_DATABASE,
80+
false,
7481
'user', false,
7582
array(),
7683
)),
@@ -84,35 +91,35 @@ public function validDsnStringProvider()
8491
array('redis://user:pass@foobar:1234', array(
8592
'foobar',
8693
1234,
87-
Resque_Redis::DEFAULT_DATABASE,
94+
false,
8895
'user', 'pass',
8996
array(),
9097
)),
9198
array('redis://user:pass@foobar:1234?x=y&a=b', array(
9299
'foobar',
93100
1234,
94-
Resque_Redis::DEFAULT_DATABASE,
101+
false,
95102
'user', 'pass',
96103
array('x' => 'y', 'a' => 'b'),
97104
)),
98105
array('redis://:pass@foobar:1234?x=y&a=b', array(
99106
'foobar',
100107
1234,
101-
Resque_Redis::DEFAULT_DATABASE,
108+
false,
102109
false, 'pass',
103110
array('x' => 'y', 'a' => 'b'),
104111
)),
105112
array('redis://user@foobar:1234?x=y&a=b', array(
106113
'foobar',
107114
1234,
108-
Resque_Redis::DEFAULT_DATABASE,
115+
false,
109116
'user', false,
110117
array('x' => 'y', 'a' => 'b'),
111118
)),
112119
array('redis://foobar:1234?x=y&a=b', array(
113120
'foobar',
114121
1234,
115-
Resque_Redis::DEFAULT_DATABASE,
122+
false,
116123
false, false,
117124
array('x' => 'y', 'a' => 'b'),
118125
)),

0 commit comments

Comments
 (0)