|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\Cache; |
|
6
|
|
|
use Doctrine\Common\Cache\PredisCache; |
|
7
|
|
|
use Predis\Client; |
|
8
|
|
|
use Predis\Connection\ConnectionException; |
|
9
|
|
|
|
|
10
|
|
|
class PredisCacheTest extends CacheTest |
|
11
|
|
|
{ |
|
12
|
|
|
private $client; |
|
13
|
|
|
|
|
14
|
|
|
protected function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
if (!class_exists('Predis\Client')) { |
|
17
|
|
|
$this->markTestSkipped('Predis\Client is missing. Make sure to "composer install" to have all dev dependencies.'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$this->client = new Client(); |
|
21
|
|
|
|
|
22
|
|
|
try { |
|
23
|
|
|
$this->client->connect(); |
|
24
|
|
|
} catch (ConnectionException $e) { |
|
25
|
|
|
$this->markTestSkipped('Cannot connect to Redis because of: ' . $e); |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testHitMissesStatsAreProvided() |
|
30
|
|
|
{ |
|
31
|
|
|
$cache = $this->_getCacheDriver(); |
|
32
|
|
|
$stats = $cache->getStats(); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertNotNull($stats[Cache::STATS_HITS]); |
|
35
|
|
|
$this->assertNotNull($stats[Cache::STATS_MISSES]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return PredisCache |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function _getCacheDriver() |
|
42
|
|
|
{ |
|
43
|
|
|
return new PredisCache($this->client); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritDoc} |
|
48
|
|
|
* |
|
49
|
|
|
* @dataProvider provideDataToCache |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testSetContainsFetchDelete($value) |
|
52
|
|
|
{ |
|
53
|
|
|
if (array() === $value) { |
|
54
|
|
|
$this->markTestIncomplete( |
|
55
|
|
|
'Predis currently doesn\'t support saving empty array values. ' |
|
56
|
|
|
. 'See https://github.com/nrk/predis/issues/241' |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
parent::testSetContainsFetchDelete($value); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
* |
|
66
|
|
|
* @dataProvider provideDataToCache |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testUpdateExistingEntry($value) |
|
69
|
|
|
{ |
|
70
|
|
|
if (array() === $value) { |
|
71
|
|
|
$this->markTestIncomplete( |
|
72
|
|
|
'Predis currently doesn\'t support saving empty array values. ' |
|
73
|
|
|
. 'See https://github.com/nrk/predis/issues/241' |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
parent::testUpdateExistingEntry($value); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testAllowsGenericPredisClient() |
|
81
|
|
|
{ |
|
82
|
|
|
/* @var $predisClient \Predis\ClientInterface */ |
|
83
|
|
|
$predisClient = $this->getMock('Predis\\ClientInterface'); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertInstanceOf('Doctrine\\Common\\Cache\\PredisCache', new PredisCache($predisClient)); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|