MemCachedTest.php 1.37 KB
Newer Older
1 2
<?php
namespace yiiunit\framework\caching;
Alexander Makarov committed
3

4 5 6
use yii\caching\MemCache;

/**
7
 * Class for testing memcached cache backend
8 9
 * @group memcached
 * @group caching
10
 */
Alexander Makarov committed
11
class MemCachedTest extends CacheTestCase
12
{
13
    private $_cacheInstance = null;
14

15 16 17 18 19 20 21 22
    /**
     * @return MemCache
     */
    protected function getCacheInstance()
    {
        if (!extension_loaded("memcached")) {
            $this->markTestSkipped("memcached not installed. Skipping.");
        }
23

24 25 26 27 28
        // check whether memcached is running and skip tests if not.
        if (!@stream_socket_client('127.0.0.1:11211', $errorNumber, $errorDescription, 0.5)) {
            $this->markTestSkipped('No redis server running at ' . '127.0.0.1:11211' . ' : ' . $errorNumber . ' - ' . $errorDescription);
        }

29 30 31
        if ($this->_cacheInstance === null) {
            $this->_cacheInstance = new MemCache(['useMemcached' => true]);
        }
32

33 34
        return $this->_cacheInstance;
    }
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    public function testExpire()
    {
        if (getenv('TRAVIS') == 'true') {
            $this->markTestSkipped('Can not reliably test memcached expiry on travis-ci.');
        }
        parent::testExpire();
    }

    public function testExpireAdd()
    {
        if (getenv('TRAVIS') == 'true') {
            $this->markTestSkipped('Can not reliably test memcached expiry on travis-ci.');
        }
        parent::testExpireAdd();
    }
Zander Baldwin committed
51
}