Passed
Pull Request — master (#30)
by Alexander
02:06
created

MemcachedTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 33
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createCacheInstance() 0 3 1
A testExpire() 0 6 2
A setUpBeforeClass() 0 9 3
A testExpireAdd() 0 6 2
1
<?php
2
namespace Yiisoft\CacheOld\Tests;
3
4
use Yiisoft\CacheOld\Cache;
5
use Yiisoft\CacheOld\CacheInterface;
6
use Yiisoft\CacheOld\Memcached;
7
8
/**
9
 * Class for testing memcached cache backend.
10
 * @group memcached
11
 * @group caching
12
 */
13
class MemcachedTest extends CacheTest
14
{
15
    public static function setUpBeforeClass(): void
16
    {
17
        if (!extension_loaded('memcached')) {
18
            self::markTestSkipped('Required extension "memcached" is not loaded');
19
        }
20
21
        // check whether memcached is running and skip tests if not.
22
        if (!@stream_socket_client('127.0.0.1:11211', $errorNumber, $errorDescription, 0.5)) {
23
            self::markTestSkipped('No memcached server running at ' . '127.0.0.1:11211' . ' : ' . $errorNumber . ' - ' . $errorDescription);
24
        }
25
    }
26
27
    protected function createCacheInstance(): CacheInterface
28
    {
29
        return new Cache(new Memcached());
30
    }
31
32
    public function testExpire(): void
33
    {
34
        if (getenv('TRAVIS') === 'true') {
35
            $this->markTestSkipped('Can not reliably test memcached expiry on travis-ci.');
36
        }
37
        parent::testExpire();
38
    }
39
40
    public function testExpireAdd(): void
41
    {
42
        if (getenv('TRAVIS') === 'true') {
43
            $this->markTestSkipped('Can not reliably test memcached expiry on travis-ci.');
44
        }
45
        parent::testExpireAdd();
46
    }
47
}
48