Completed
Push — master ( 1fce20...c903a9 )
by Daniel
03:12
created

PublisherTest::getChannelMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
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
    public function testGetQueueName()
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 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...
53
    {
54
        $publisher = new Publisher(
55
            'exch_test',
56
            ExchangeType::FANOUT,
57
            $this->getConnectionManagerMock(),
58
            'caller_test',
59
            ''
60
        );
61
62
        $this->assertEquals('caller_test', $publisher->getFromName());
63
    }
64
65
    /**
66
     * @return ConnectionManager
67
     */
68 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...
69
    {
70
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
71
            ->disableOriginalConstructor()
72
            ->getMock();
73
        $connectionManagerMock->method('getConnection')
74
            ->willReturn($this->getConnectionMock());
75
76
        return $connectionManagerMock;
77
    }
78
79
    /**
80
     * @return CmobiAMQPConnection
81
     */
82 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...
83
    {
84
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
85
            ->disableOriginalConstructor()
86
            ->getMock();
87
        $connectionMock->method('isConnected')
88
            ->willReturn(true);
89
        $connectionMock->method('reconnect')
90
            ->willReturn(true);
91
        $connectionMock->method('channel')
92
            ->willReturn($this->getChannelMock());
93
94
        return $connectionMock;
95
    }
96
97
    /**
98
     * @return CmobiAMQPChannel
99
     */
100 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...
101
    {
102
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
103
            ->disableOriginalConstructor()
104
            ->getMock();
105
        $channelMock
106
            ->expects($this->any())
107
            ->method('basic_publish')
108
            ->willReturn(true);
109
        $channelMock
110
            ->method('basicConsume')
111
            ->willReturn(true);
112
113
        return $channelMock;
114
    }
115
116
    /**
117
     * @param string $msg
118
     * @param null   $correlationId
119
     *
120
     * @return CmobiAMQPMessage
121
     */
122 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...
123
    {
124
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
125
            ->disableOriginalConstructor()
126
            ->getMock();
127
        $msgMock->method('get')
128
            ->willReturn('correlation_id')
129
            ->willReturn($correlationId);
130
        $msgMock->method('getBody')
131
            ->willReturn($msg);
132
133
        return $msgMock;
134
    }
135
}
136