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

MemcachedTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExpire() 0 7 2
A createCacheInstance() 0 5 1
A setUpBeforeClass() 0 9 3
A testDeleteMultipleReturnsFalse() 0 10 1
1
<?php
2
3
4
namespace Yiisoft\Cache\Tests\Memcached;
5
6
7
use Psr\SimpleCache\CacheInterface;
8
use Yiisoft\Cache\Memcached;
9
use Yiisoft\Cache\MemcachedServer;
10
use Yiisoft\Cache\Tests\BaseTest;
11
12
class MemcachedTest extends BaseTest
13
{
14
    public static function setUpBeforeClass(): void
15
    {
16
        if (!extension_loaded('memcached')) {
17
            self::markTestSkipped('Required extension "memcached" is not loaded');
18
        }
19
20
        // check whether memcached is running and skip tests if not.
21
        if (!@stream_socket_client('127.0.0.1:11211', $errorNumber, $errorDescription, 0.5)) {
22
            self::markTestSkipped('No memcached server running at ' . '127.0.0.1:11211' . ' : ' . $errorNumber . ' - ' . $errorDescription);
23
        }
24
    }
25
26
    protected function createCacheInstance(): CacheInterface
27
    {
28
        $cache = new Memcached();
29
        $cache->addServer(new MemcachedServer('127.0.0.1'));
30
        return $cache;
31
    }
32
33
    public function testDeleteMultipleReturnsFalse(): void
34
    {
35
        $cache = new Memcached();
36
37
        $memcachedStub = $this->createMock(\Memcached::class);
38
        $memcachedStub->method('deleteMulti')->willReturn([false]);
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        $memcachedStub->/** @scrutinizer ignore-call */ 
39
                        method('deleteMulti')->willReturn([false]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
40
        $this->setInaccessibleProperty($cache, 'cache', $memcachedStub);
41
42
        $this->assertFalse($cache->deleteMultiple(['a', 'b']));
43
    }
44
45
    public function testExpire(): void
46
    {
47
        if (getenv('TRAVIS') === 'true') {
48
            $this->markTestSkipped('Can not reliably test memcached expiry on travis-ci.');
49
        }
50
        // TODO
51
        $this->assertTrue(true);
52
        //parent::testExpire();
53
    }
54
}
55