Completed
Push — master ( e9401f...2161bf )
by Daniel
03:27
created

PublisherTest::testRefreshChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Tests\Transport\Subscriber;
4
5
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel;
6
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnection;
7
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
8
use Cmobi\RabbitmqBundle\Queue\CmobiAMQPMessage;
9
use Cmobi\RabbitmqBundle\Tests\BaseTestCase;
10
use Cmobi\RabbitmqBundle\Transport\Subscriber\ExchangeType;
11
use Cmobi\RabbitmqBundle\Transport\Subscriber\Publisher;
12
13
class PublisherTest extends BaseTestCase
14
{
15 View Code Duplication
    public function testGetQueueName()
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...
16
    {
17
        $publisher = new Publisher(
18
            'exch_test',
19
            ExchangeType::FANOUT,
20
            $this->getConnectionManagerMock(),
21
            'from_name_test',
22
            'test'
23
        );
24
25
        $this->assertEquals('test', $publisher->getQueueName());
26
    }
27
28
    public function testGetExchange()
29
    {
30
        $publisher = new Publisher(
31
            'exch_test',
32
            ExchangeType::FANOUT,
33
            $this->getConnectionManagerMock(),
34
            'test'
35
        );
36
37
        $this->assertEquals('exch_test', $publisher->getExchange());
38
    }
39
40 View Code Duplication
    public function testGetExchangeType()
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...
41
    {
42
        $publisher = new Publisher(
43
            'exch_test',
44
            ExchangeType::DIRECT,
45
            $this->getConnectionManagerMock(),
46
            'test'
47
        );
48
49
        $this->assertEquals(ExchangeType::DIRECT, $publisher->getExchangeType());
50
    }
51
52 View Code Duplication
    public function testRefreshChannel()
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...
53
    {
54
        $publisher = new Publisher(
55
            'exch_test',
56
            ExchangeType::FANOUT,
57
            $this->getConnectionManagerMock(),
58
            'test'
59
        );
60
61
        $this->assertInstanceOf(CmobiAMQPChannel::class, $publisher->refreshChannel());
62
    }
63
64 View Code Duplication
    public function testGetChannel()
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...
65
    {
66
        $publisher = new Publisher(
67
            'exch_test',
68
            ExchangeType::FANOUT,
69
            $this->getConnectionManagerMock(),
70
            'test'
71
        );
72
73
        $this->assertInstanceOf(CmobiAMQPChannel::class, $publisher->refreshChannel());
74
    }
75
76 View Code Duplication
    public function testGetFromName()
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...
77
    {
78
        $publisher = new Publisher(
79
            'exch_test',
80
            ExchangeType::FANOUT,
81
            $this->getConnectionManagerMock(),
82
            'caller_test',
83
            ''
84
        );
85
86
        $this->assertEquals('caller_test', $publisher->getFromName());
87
    }
88
89
    /**
90
     * @return ConnectionManager
91
     */
92 View Code Duplication
    protected function getConnectionManagerMock()
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...
93
    {
94
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
95
            ->disableOriginalConstructor()
96
            ->getMock();
97
        $connectionManagerMock->method('getConnection')
98
            ->willReturn($this->getConnectionMock());
99
100
        return $connectionManagerMock;
101
    }
102
103
    /**
104
     * @return CmobiAMQPConnection
105
     */
106 View Code Duplication
    protected function getConnectionMock()
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...
107
    {
108
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
109
            ->disableOriginalConstructor()
110
            ->getMock();
111
        $connectionMock->method('isConnected')
112
            ->willReturn(true);
113
        $connectionMock->method('reconnect')
114
            ->willReturn(true);
115
        $connectionMock->method('channel')
116
            ->willReturn($this->getChannelMock());
117
118
        return $connectionMock;
119
    }
120
121
    /**
122
     * @return CmobiAMQPChannel
123
     */
124 View Code Duplication
    protected function getChannelMock()
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...
125
    {
126
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
127
            ->disableOriginalConstructor()
128
            ->getMock();
129
        $channelMock
130
            ->expects($this->any())
131
            ->method('basic_publish')
132
            ->willReturn(true);
133
        $channelMock
134
            ->method('basicConsume')
135
            ->willReturn(true);
136
137
        return $channelMock;
138
    }
139
140
    /**
141
     * @param string $msg
142
     * @param null   $correlationId
143
     *
144
     * @return CmobiAMQPMessage
145
     */
146 View Code Duplication
    protected function getCmobiAMQPMessage($msg = '', $correlationId = null)
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...
147
    {
148
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
149
            ->disableOriginalConstructor()
150
            ->getMock();
151
        $msgMock->method('get')
152
            ->willReturn('correlation_id')
153
            ->willReturn($correlationId);
154
        $msgMock->method('getBody')
155
            ->willReturn($msg);
156
157
        return $msgMock;
158
    }
159
}
160