2014-05-05 13:02:16 +00:00
|
|
|
<?php
|
2018-05-25 07:26:54 +00:00
|
|
|
|
2014-05-05 13:02:16 +00:00
|
|
|
/**
|
2015-02-02 22:00:16 +00:00
|
|
|
* Resque_Event tests.
|
2014-05-05 13:02:16 +00:00
|
|
|
*
|
2018-05-25 07:26:54 +00:00
|
|
|
* @package Resque/Tests
|
|
|
|
* @author Chris Boulton <chris@bigcommerce.com>
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
2014-05-05 13:02:16 +00:00
|
|
|
*/
|
2018-05-25 07:26:54 +00:00
|
|
|
|
2015-02-02 22:00:16 +00:00
|
|
|
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
2014-05-05 13:02:16 +00:00
|
|
|
{
|
2018-05-25 08:11:17 +00:00
|
|
|
public function testRedisGetSet()
|
|
|
|
{
|
|
|
|
$this->redis->set("testKey", 24);
|
|
|
|
$val = $this->redis->get("testKey");
|
|
|
|
$this->assertEquals(24, $val);
|
|
|
|
}
|
2016-10-15 08:44:03 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
/**
|
|
|
|
* These DNS strings are considered valid.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function validDsnStringProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
// Input , Expected output
|
|
|
|
['', [
|
|
|
|
'localhost',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['localhost', [
|
|
|
|
'localhost',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['localhost:1234', [
|
|
|
|
'localhost',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['localhost:1234/2', [
|
|
|
|
'localhost',
|
|
|
|
1234,
|
|
|
|
2,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://foobar', [
|
|
|
|
'foobar',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://foobar/', [
|
|
|
|
'foobar',
|
|
|
|
Resque_Redis::DEFAULT_PORT,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://foobar:1234', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://foobar:1234/15', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
15,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://foobar:1234/0', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
0,
|
|
|
|
false, false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://user@foobar:1234', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
'user', false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://user@foobar:1234/15', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
15,
|
|
|
|
'user', false,
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://user:pass@foobar:1234', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
'user', 'pass',
|
|
|
|
[],
|
|
|
|
]],
|
|
|
|
['redis://user:pass@foobar:1234?x=y&a=b', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
'user', 'pass',
|
|
|
|
['x' => 'y', 'a' => 'b'],
|
|
|
|
]],
|
|
|
|
['redis://:pass@foobar:1234?x=y&a=b', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
false, 'pass',
|
|
|
|
['x' => 'y', 'a' => 'b'],
|
|
|
|
]],
|
|
|
|
['redis://user@foobar:1234?x=y&a=b', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
'user', false,
|
|
|
|
['x' => 'y', 'a' => 'b'],
|
|
|
|
]],
|
|
|
|
['redis://foobar:1234?x=y&a=b', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
false, false,
|
|
|
|
['x' => 'y', 'a' => 'b'],
|
|
|
|
]],
|
|
|
|
['redis://user@foobar:1234/12?x=y&a=b', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
12,
|
|
|
|
'user', false,
|
|
|
|
['x' => 'y', 'a' => 'b'],
|
|
|
|
]],
|
|
|
|
['tcp://user@foobar:1234/12?x=y&a=b', [
|
|
|
|
'foobar',
|
|
|
|
1234,
|
|
|
|
12,
|
|
|
|
'user', false,
|
|
|
|
['x' => 'y', 'a' => 'b'],
|
|
|
|
]],
|
|
|
|
];
|
|
|
|
}
|
2014-05-05 13:02:16 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
/**
|
|
|
|
* These DSN values should throw exceptions
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function bogusDsnStringProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['http://foo.bar/'],
|
|
|
|
['user:@foobar:1234?x=y&a=b'],
|
|
|
|
['foobar:1234?x=y&a=b'],
|
|
|
|
];
|
|
|
|
}
|
2014-05-05 13:02:16 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider validDsnStringProvider
|
2018-05-29 20:25:02 +00:00
|
|
|
* @param $dsn
|
|
|
|
* @param $expected
|
2018-05-25 07:26:54 +00:00
|
|
|
*/
|
|
|
|
public function testParsingValidDsnString($dsn, $expected)
|
|
|
|
{
|
|
|
|
$result = Resque_Redis::parseDsn($dsn);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2014-05-05 13:02:16 +00:00
|
|
|
|
2018-05-25 07:26:54 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider bogusDsnStringProvider
|
2020-04-10 21:24:18 +00:00
|
|
|
*
|
2018-05-25 07:26:54 +00:00
|
|
|
* @expectedException InvalidArgumentException
|
2020-04-10 21:24:18 +00:00
|
|
|
*
|
2018-05-29 20:25:02 +00:00
|
|
|
* @param $dsn
|
2018-05-25 07:26:54 +00:00
|
|
|
*/
|
|
|
|
public function testParsingBogusDsnStringThrowsException($dsn)
|
|
|
|
{
|
2020-04-10 21:24:18 +00:00
|
|
|
$this->expectException(InvalidArgumentException::class);
|
2018-05-25 07:26:54 +00:00
|
|
|
Resque_Redis::parseDsn($dsn);
|
|
|
|
}
|
2015-02-02 22:00:16 +00:00
|
|
|
}
|