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

MemcacheCacheTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 49
rs 10
1
<?php
2
3
namespace Doctrine\Tests\Common\Cache;
4
5
use Doctrine\Common\Cache\CacheProvider;
6
use Doctrine\Common\Cache\MemcacheCache;
7
use Memcache;
8
9
/**
10
 * @requires extension memcache
11
 */
12
class MemcacheCacheTest extends CacheTest
13
{
14
    private $memcache;
15
16
    protected function setUp() : void
17
    {
18
        $this->memcache = new Memcache();
19
20
        if (@$this->memcache->connect('localhost', 11211) !== false) {
21
            return;
22
        }
23
24
        unset($this->memcache);
25
        $this->markTestSkipped('Cannot connect to Memcache.');
26
    }
27
28
    protected function tearDown() : void
29
    {
30
        if (! ($this->memcache instanceof Memcache)) {
31
            return;
32
        }
33
34
        $this->memcache->flush();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * Memcache does not support " " and null byte as key so we remove them from the tests.
41
     */
42
    public function provideCacheIds() : array
43
    {
44
        $ids = parent::provideCacheIds();
45
        unset($ids[21], $ids[22]);
46
47
        return $ids;
48
    }
49
50
    public function testGetMemcacheReturnsInstanceOfMemcache() : void
51
    {
52
        self::assertInstanceOf('Memcache', $this->_getCacheDriver()->getMemcache());
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    protected function _getCacheDriver() : CacheProvider
59
    {
60
        $driver = new MemcacheCache();
61
        $driver->setMemcache($this->memcache);
62
        return $driver;
63
    }
64
}
65