Completed
Push — master ( e1f38a...73ba45 )
by Marco
10s
created

PredisCacheTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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