BindingTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 49
c 2
b 0
f 0
dl 0
loc 79
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testExhangeBind() 0 24 1
A getBinding() 0 3 1
A prepareAMQPConnection() 0 5 1
A testQueueBind() 0 23 1
A prepareAMQPChannel() 0 10 1
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Tests\RabbitMq;
4
5
use OldSound\RabbitMqBundle\RabbitMq\Binding;
6
use PHPUnit\Framework\Assert;
7
use PHPUnit\Framework\MockObject\MockObject;
8
use PHPUnit\Framework\TestCase;
9
10
class BindingTest extends TestCase
11
{
12
13
    protected function getBinding($amqpConnection, $amqpChannel)
14
    {
15
        return new Binding($amqpConnection, $amqpChannel);
16
    }
17
18
    /**
19
     * @return MockObject
20
     */
21
    protected function prepareAMQPConnection()
22
    {
23
        return $this->getMockBuilder('\PhpAmqpLib\Connection\AMQPStreamConnection')
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
    }
27
28
    protected function prepareAMQPChannel($channelId = null)
29
    {
30
        $channelMock = $this->getMockBuilder('\PhpAmqpLib\Channel\AMQPChannel')
31
            ->disableOriginalConstructor()
32
            ->getMock();
33
34
        $channelMock->expects($this->any())
35
            ->method('getChannelId')
36
            ->willReturn($channelId);
37
        return $channelMock;
38
    }
39
40
    public function testQueueBind()
41
    {
42
        $ch = $this->prepareAMQPChannel('channel_id');
43
        $con = $this->prepareAMQPConnection();
44
45
        $source = 'example_source';
46
        $destination = 'example_destination';
47
        $key = 'example_key';
48
        $ch->expects($this->once())
49
            ->method('queue_bind')
50
            ->will($this->returnCallback(function ($d, $s, $k, $n, $a) use ($destination, $source, $key) {
51
                Assert::assertSame($destination, $d);
52
                Assert::assertSame($source, $s);
53
                Assert::assertSame($key, $k);
54
                Assert::assertFalse($n);
55
                Assert::assertNull($a);
56
            }));
57
58
        $binding = $this->getBinding($con, $ch);
59
        $binding->setExchange($source);
60
        $binding->setDestination($destination);
61
        $binding->setRoutingKey($key);
62
        $binding->setupFabric();
63
    }
64
65
    public function testExhangeBind()
66
    {
67
        $ch = $this->prepareAMQPChannel('channel_id');
68
        $con = $this->prepareAMQPConnection();
69
70
        $source = 'example_source';
71
        $destination = 'example_destination';
72
        $key = 'example_key';
73
        $ch->expects($this->once())
74
            ->method('exchange_bind')
75
            ->will($this->returnCallback(function ($d, $s, $k, $n, $a) use ($destination, $source, $key) {
76
                Assert::assertSame($destination, $d);
77
                Assert::assertSame($source, $s);
78
                Assert::assertSame($key, $k);
79
                Assert::assertFalse($n);
80
                Assert::assertNull($a);
81
            }));
82
83
        $binding = $this->getBinding($con, $ch);
84
        $binding->setExchange($source);
85
        $binding->setDestination($destination);
86
        $binding->setRoutingKey($key);
87
        $binding->setDestinationIsExchange(true);
88
        $binding->setupFabric();
89
    }
90
}
91