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

PermissionManagerTest::test_define_create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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