Completed
Push — master ( a8b991...dda2b8 )
by Marco
06:05 queued 02:56
created

MemcacheCacheTest::_getCacheDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

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