MutexAdapterTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 36.23 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 25
loc 69
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A shouldAcquireMutex() 0 7 1
A shouldThrowAnExceptionIfMutexIsAlreadyAcquired() 9 9 1
A shouldReleaseMutex() 7 7 1
A shouldThrowAnExceptionIfCantReleaseTheMutex() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Tests\AMF\Mutex;
11
12
use AMF\Mutex\MutexInterface;
13
use AMF\Mutex\MutexAdapter;
14
15
/**
16
 * Test suite for adapter of mutex.
17
 *
18
 * @author Amine Fattouch <[email protected]>
19
 */
20
class MutexAdapterTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var \Phake_IMock
24
     */
25
    protected $mutex;
26
27
    /**
28
     * @var \Phake_IMock
29
     */
30
    protected $mutexAdapter;
31
32
    /**
33
     *
34
     */
35
    public function setUp()
36
    {
37
        $this->mutex        = \Phake::partialMock(MutexInterface::class);
38
        $this->mutexAdapter = \Phake::partialMock(MutexAdapter::class, $this->mutex, 10, 0);
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function shouldAcquireMutex()
45
    {
46
        \Phake::when($this->mutexAdapter)->generateKey($this->anything())->thenReturn('worker_test');
47
        \Phake::when($this->mutex)->acquire($this->anything(), $this->anything())->thenReturn('worker_test');
48
49
        $this->assertEquals('worker_test', $this->mutexAdapter->acquire('test'));
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...
50
    }
51
52
    /**
53
     * @test
54
     */
55 View Code Duplication
    public function shouldThrowAnExceptionIfMutexIsAlreadyAcquired()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $this->setExpectedExceptionRegExp(\RuntimeException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCa...pectedExceptionRegExp() has been deprecated with message: Method deprecated since Release 5.6.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
58
59
        \Phake::when($this->mutexAdapter)->generateKey($this->anything())->thenReturn('worker_test');
60
        \Phake::when($this->mutex)->acquire($this->anything(), $this->anything())->thenReturn(null);
61
62
        $this->mutexAdapter->acquire('test');
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...
63
    }
64
65
    /**
66
     * @test
67
     */
68 View Code Duplication
    public function shouldReleaseMutex()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        \Phake::when($this->mutexAdapter)->generateKey('test')->thenReturn('worker_test');
71
        \Phake::when($this->mutex)->release($this->anything(), $this->anything())->thenReturn(true);
72
73
        $this->assertNull($this->mutexAdapter->release('worker_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...
74
    }
75
76
    /**
77
     * @test
78
     */
79 View Code Duplication
    public function shouldThrowAnExceptionIfCantReleaseTheMutex()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $this->setExpectedExceptionRegExp(\RuntimeException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCa...pectedExceptionRegExp() has been deprecated with message: Method deprecated since Release 5.6.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
82
83
        \Phake::when($this->mutexAdapter)->generateKey($this->anything())->thenReturn('worker_test');
84
        \Phake::when($this->mutex)->release($this->anything())->thenReturn(false);
85
86
        $this->mutexAdapter->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...
87
    }
88
}
89