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

ExchangeManagerTest::test_define_create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Ola\RabbitMqAdminToolkitBundle\Tests\Manager;
4
5
use Ola\RabbitMqAdminToolkitBundle\Manager\ExchangeManager;
6
7
class ExchangeManagerTest extends AbstractManagerTest
8
{
9
    private $exchanges;
10
    private $exchangeManager;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        $this->exchanges = $this->prophesize('RabbitMq\ManagementApi\Api\Exchange');
17
        $this->client->exchanges()->willReturn($this->exchanges->reveal());
18
        $this->configuration->isDeleteAllowed()->willReturn(false);
19
20
        $this->exchangeManager = new ExchangeManager();
21
    }
22
23
    public function test_define_create()
24
    {
25
        $this->configuration->getConfiguration('exchanges')->willReturn(array(
26
            'foo' => array(),
27
            'bar' => array('name' => 'doe')
28
        ));
29
30
        $exception = $this->get404Exception();
31
        $this->exchanges->get('vhost', 'foo')->willThrow($exception->reveal());
32
        $this->exchanges->get('vhost', 'doe')->willThrow($exception->reveal());
33
34
        $this->exchanges->create('vhost', 'foo', array())->shouldBeCalled();
35
        $this->exchanges->create('vhost', 'doe', array())->shouldBeCalled();
36
37
        $this->exchangeManager->define($this->configuration->reveal());
38
    }
39
40
    public function test_define_exist()
41
    {
42
        $this->configuration->getConfiguration('exchanges')->willReturn(array(
43
            'foo' => array(),
44
            'bar' => array('name' => 'doe')
45
        ));
46
47
        $this->exchanges->get('vhost', 'foo')->willReturn(array());
48
        $this->exchanges->get('vhost', 'doe')->willReturn(array());
49
50
        $this->exchanges->create('vhost', 'foo', array())->shouldNotBeCalled();
51
        $this->exchanges->create('vhost', 'doe', array())->shouldNotBeCalled();
52
53
        $this->exchangeManager->define($this->configuration->reveal());
54
    }
55
56
    public function test_define_update()
57
    {
58
        $this->configuration->getConfiguration('exchanges')->willReturn(array(
59
            'foo' => array('durable' => true),
60
            'bar' => array('name' => 'doe', 'durable' => true)
61
        ));
62
63
        $this->configuration->isDeleteAllowed()->willReturn(true);
64
65
        $this->exchanges->get('vhost', 'foo')->willReturn(array('durable' => true));
66
        $this->exchanges->get('vhost', 'doe')->willReturn(array('durable' => false));
67
68
        $this->exchanges->create('vhost', 'foo', array('durable' => true))->shouldNotBeCalled();
69
        $this->exchanges->delete('vhost', 'doe')->shouldBeCalled();
70
        $this->exchanges->create('vhost', 'doe', array('durable' => true))->shouldBeCalled();
71
72
        $this->exchangeManager->define($this->configuration->reveal());
73
    }
74
}
75