MemcachedMutexTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A shouldReturnKeyIfMutexIsAcquired() 0 6 1
A shouldRetunNullIFMutexIsNotAcquired() 0 6 1
A shouldReleaseMutex() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the Mutex Library.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace AMF\Mutex\Tests\Adapter;
11
12
use AMF\Mutex\Adapter\MemcachedMutex;
13
14
/**
15
 * Test suite for memcached mutex.
16
 *
17
 * @author Amine Fattouch <[email protected]>
18
 */
19
class MemcachedMutexTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var \Phake_IMock
23
     */
24
    private $memcached;
25
26
    /**
27
     * @var \Phake_IMock
28
     */
29
    private $memcachedMutex;
30
31
    /**
32
     *
33
     */
34
    public function setUp()
35
    {
36
        $this->memcached      = \Phake::partialMock(\Memcached::class);
37
        $this->memcachedMutex = \Phake::partialMock(MemcachedMutex::class, $this->memcached);
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function shouldReturnKeyIfMutexIsAcquired()
44
    {
45
        \Phake::when($this->memcached)->add($this->anything(), $this->anything(), $this->anything())->thenReturn(true);
46
47
        $this->assertEquals('test', $this->memcachedMutex->acquire('test', 60));
0 ignored issues
show
Bug introduced by
The method acquire() does not seem to exist on object<Phake_IMock>.

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...
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function shouldRetunNullIFMutexIsNotAcquired()
54
    {
55
        \Phake::when($this->memcached)->add('test', $this->anything(), $this->anything())->thenReturn(false);
56
57
        $this->assertNull($this->memcachedMutex->acquire('test', 60));
0 ignored issues
show
Bug introduced by
The method acquire() does not seem to exist on object<Phake_IMock>.

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...
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function shouldReleaseMutex()
64
    {
65
        \Phake::when($this->memcached)->get($this->anything())->thenReturn(true);
66
67
        $this->memcachedMutex->release('test');
0 ignored issues
show
Bug introduced by
The method release() does not seem to exist on object<Phake_IMock>.

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...
68
69
        \Phake::verify($this->memcached)->delete($this->anything());
70
    }
71
}
72