Completed
Push — master ( 627c37...9fcd11 )
by Olivier
03:49 queued 01:55
created

PermissionManagerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 45.16 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 28
loc 62
rs 10

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
namespace Ola\RabbitMqAdminToolkitBundle\Tests\Manager;
4
5
use Ola\RabbitMqAdminToolkitBundle\Manager\PermissionManager;
6
7
class PermissionManagerTest extends AbstractManagerTest
8
{
9
    private $permissions;
10
    private $permissionManager;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        $this->permissions = $this->prophesize('RabbitMq\ManagementApi\Api\Permission');
17
        $this->client->permissions()->willReturn($this->permissions->reveal());
18
        $this->configuration->isDeleteAllowed()->willReturn(false);
19
20
        $this->permissionManager = new PermissionManager();
21
    }
22
23
    public function test_define_create()
24
    {
25
        $this->configuration->getConfiguration('permissions')->willReturn(array(
26
            'foo' => array(),
27
        ));
28
29
        $exception = $this->get404Exception();
30
        $this->permissions->get('vhost', 'foo')->willThrow($exception->reveal());
31
32
        $this->permissions->create('vhost', 'foo', array())->shouldBeCalled();
33
34
        $this->permissionManager->define($this->configuration->reveal());
35
    }
36
37
    public function test_define_exist()
38
    {
39
        $this->configuration->getConfiguration('permissions')->willReturn(array(
40
            'foo' => array(),
41
        ));
42
43
        $this->permissions->get('vhost', 'foo')->willReturn(array());
44
45
        $this->permissions->create('vhost', 'foo', array())->shouldNotBeCalled();
46
47
        $this->permissionManager->define($this->configuration->reveal());
48
    }
49
50
    public function test_define_update()
51
    {
52
        $this->configuration->getConfiguration('permissions')->willReturn(array(
53
            'foo' => array('durable' => true),
54
            'bar' => array('durable' => true)
55
        ));
56
57
        $this->configuration->isDeleteAllowed()->willReturn(true);
58
59
        $this->permissions->get('vhost', 'foo')->willReturn(array('durable' => true));
60
        $this->permissions->get('vhost', 'bar')->willReturn(array('durable' => false));
61
62
        $this->permissions->create('vhost', 'foo', array('durable' => true))->shouldNotBeCalled();
63
        $this->permissions->delete('vhost', 'bar')->shouldBeCalled();
64
        $this->permissions->create('vhost', 'bar', array('durable' => true))->shouldBeCalled();
65
66
        $this->permissionManager->define($this->configuration->reveal());
67
    }
68
}
69