2014-05-05 13:02:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-02-02 22:00:16 +00:00
|
|
|
* Resque_Event tests.
|
2014-05-05 13:02:16 +00:00
|
|
|
*
|
|
|
|
* @package Resque/Tests
|
2015-02-02 22:00:16 +00:00
|
|
|
* @author Chris Boulton <chris@bigcommerce.com>
|
2014-05-05 13:02:16 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
|
|
|
*/
|
2015-02-02 22:00:16 +00:00
|
|
|
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
2014-05-05 13:02:16 +00:00
|
|
|
{
|
2015-02-02 22:00:16 +00:00
|
|
|
/**
|
|
|
|
* @expectedException Resque_RedisException
|
|
|
|
*/
|
|
|
|
public function testRedisExceptionsAreSurfaced()
|
|
|
|
{
|
|
|
|
$redis = new Resque_Redis('redis://255.255.255.255:1234');
|
|
|
|
$redis->ping();
|
|
|
|
}
|
2014-05-05 13:02:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These DNS strings are considered valid.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function validDsnStringProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
// Input , Expected output
|
|
|
|
array('', array(
|
|
|
|
'localhost',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
|
|
|
array('localhost', array(
|
|
|
|
'localhost',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
|
|
|
array('localhost:1234', array(
|
|
|
|
'localhost',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
|
|
|
array('localhost:1234/2', array(
|
|
|
|
'localhost',
|
|
|
|
1234,
|
|
|
|
2,
|
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
|
|
|
array('redis://foobar', array(
|
|
|
|
'foobar',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 15:29:52 +00:00
|
|
|
array('redis://foobar/', array(
|
|
|
|
'foobar',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 13:02:16 +00:00
|
|
|
array('redis://foobar:1234', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 14:47:43 +00:00
|
|
|
array('redis://foobar:1234/15', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
15,
|
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 14:55:01 +00:00
|
|
|
array('redis://foobar:1234/0', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
0,
|
|
|
|
false, false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 13:02:16 +00:00
|
|
|
array('redis://user@foobar:1234', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
'user', false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 14:47:43 +00:00
|
|
|
array('redis://user@foobar:1234/15', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
15,
|
|
|
|
'user', false,
|
|
|
|
array(),
|
|
|
|
)),
|
2014-05-05 13:02:16 +00:00
|
|
|
array('redis://user:pass@foobar:1234', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
'user', 'pass',
|
|
|
|
array(),
|
|
|
|
)),
|
|
|
|
array('redis://user:pass@foobar:1234?x=y&a=b', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
'user', 'pass',
|
|
|
|
array('x' => 'y', 'a' => 'b'),
|
|
|
|
)),
|
|
|
|
array('redis://:pass@foobar:1234?x=y&a=b', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, 'pass',
|
|
|
|
array('x' => 'y', 'a' => 'b'),
|
|
|
|
)),
|
|
|
|
array('redis://user@foobar:1234?x=y&a=b', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
'user', false,
|
|
|
|
array('x' => 'y', 'a' => 'b'),
|
|
|
|
)),
|
|
|
|
array('redis://foobar:1234?x=y&a=b', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
2014-05-05 14:55:01 +00:00
|
|
|
false,
|
2014-05-05 13:02:16 +00:00
|
|
|
false, false,
|
|
|
|
array('x' => 'y', 'a' => 'b'),
|
|
|
|
)),
|
|
|
|
array('redis://user@foobar:1234/12?x=y&a=b', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
12,
|
|
|
|
'user', false,
|
|
|
|
array('x' => 'y', 'a' => 'b'),
|
|
|
|
)),
|
|
|
|
array('tcp://user@foobar:1234/12?x=y&a=b', array(
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
12,
|
|
|
|
'user', false,
|
|
|
|
array('x' => 'y', 'a' => 'b'),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These DSN values should throw exceptions
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function bogusDsnStringProvider()
|
|
|
|
{
|
|
|
|
return array(
|
2014-05-05 15:29:52 +00:00
|
|
|
array('http://foo.bar/'),
|
|
|
|
array('user:@foobar:1234?x=y&a=b'),
|
|
|
|
array('foobar:1234?x=y&a=b'),
|
2014-05-05 13:02:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider validDsnStringProvider
|
|
|
|
*/
|
|
|
|
public function testParsingValidDsnString($dsn, $expected)
|
|
|
|
{
|
2014-05-05 15:08:00 +00:00
|
|
|
$result = Resque_Redis::parseDsn($dsn);
|
2014-05-05 13:02:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider bogusDsnStringProvider
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testParsingBogusDsnStringThrowsException($dsn)
|
|
|
|
{
|
|
|
|
// The next line should throw an InvalidArgumentException
|
2014-05-05 15:08:00 +00:00
|
|
|
$result = Resque_Redis::parseDsn($dsn);
|
2014-05-05 13:02:16 +00:00
|
|
|
}
|
2015-02-02 22:00:16 +00:00
|
|
|
}
|