RpcClientTest::getCmobiAMQPMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 10
nc 1
nop 2
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Tests\Transport\Rpc;
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\Transport\Rpc\RpcClient;
10
use Cmobi\RabbitmqBundle\Tests\BaseTestCase;
11
12
class RpcClientTest extends BaseTestCase
13
{
14
    public function testGetQueueName()
15
    {
16
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'test');
17
18
        $this->assertEquals('test', $rpcClient->getQueueName());
19
    }
20
21
    public function testRefreshChannel()
22
    {
23
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'test');
24
25
        $this->assertInstanceOf(CmobiAMQPChannel::class, $rpcClient->refreshChannel());
0 ignored issues
show
Bug introduced by
The method refreshChannel() does not seem to exist on object<Cmobi\RabbitmqBun...ransport\Rpc\RpcClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
    }
27
28
    public function testGetChannel()
29
    {
30
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'test');
31
32
        $this->assertInstanceOf(CmobiAMQPChannel::class, $rpcClient->refreshChannel());
0 ignored issues
show
Bug introduced by
The method refreshChannel() does not seem to exist on object<Cmobi\RabbitmqBun...ransport\Rpc\RpcClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
35
    public function testGetFromName()
36
    {
37
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'caller_test');
38
39
        $this->assertEquals('caller_test', $rpcClient->getFromName());
40
    }
41
42 View Code Duplication
    public function testGetResponse()
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...
43
    {
44
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'caller_test');
45
46
        $rpcClient->publish('test');
47
        /* @Todo prevent infinite while - improve it */
48
        $rpcClient->setResponse('testGetResponse() - OK');
49
50
        $rpcClient->onResponse(
51
            $this->getCmobiAMQPMessage('testGetResponse() - OK',
52
                $rpcClient->getCurrentCorrelationId())
53
        );
54
55
        $this->assertEquals('testGetResponse() - OK', $rpcClient->getResponse());
56
    }
57
58
    public function testGenerateCorrelationId()
59
    {
60
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'caller_test');
61
62
        $this->assertRegExp(sprintf('/%s/', $rpcClient->getCurrentCorrelationId()), $rpcClient->getQueueName());
63
    }
64
65 View Code Duplication
    public function testGetCurrentCorrelationId()
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...
66
    {
67
        $rpcClient = new RpcClient('test', $this->getConnectionManagerMock(), 'caller_test');
68
        /* @Todo prevent infinite while - improve it */
69
        $rpcClient->setResponse('testGetResponse() - OK');
70
71
        $rpcClient->publish('test');
72
        $rpcClient->onResponse(
73
            $this->getCmobiAMQPMessage('testGetResponse() - OK',
74
                $rpcClient->getCurrentCorrelationId())
75
        );
76
        $this->assertNotNull($rpcClient->getCurrentCorrelationId());
77
    }
78
79
    /**
80
     * @return ConnectionManager
81
     */
82 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...
83
    {
84
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
85
            ->disableOriginalConstructor()
86
            ->getMock();
87
        $connectionManagerMock->method('getConnection')
88
            ->willReturn($this->getConnectionMock());
89
90
        return $connectionManagerMock;
91
    }
92
93
    /**
94
     * @return CmobiAMQPConnection
95
     */
96 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...
97
    {
98
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
99
            ->disableOriginalConstructor()
100
            ->getMock();
101
        $connectionMock->method('isConnected')
102
            ->willReturn(true);
103
        $connectionMock->method('reconnect')
104
            ->willReturn(true);
105
        $connectionMock->method('channel')
106
            ->willReturn($this->getChannelMock());
107
108
        return $connectionMock;
109
    }
110
111
    /**
112
     * @return CmobiAMQPChannel
113
     */
114 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...
115
    {
116
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
117
            ->disableOriginalConstructor()
118
            ->getMock();
119
        $channelMock
120
            ->expects($this->any())
121
            ->method('basic_publish')
122
            ->willReturn(true);
123
        $channelMock
124
            ->method('basicConsume')
125
            ->willReturn(true);
126
127
        return $channelMock;
128
    }
129
130
    /**
131
     * @param string $msg
132
     * @param null   $correlationId
133
     *
134
     * @return CmobiAMQPMessage
135
     */
136 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...
137
    {
138
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
139
            ->disableOriginalConstructor()
140
            ->getMock();
141
        $msgMock->method('get')
142
            ->willReturn('correlation_id')
143
            ->willReturn($correlationId);
144
        $msgMock->method('getBody')
145
            ->willReturn($msg);
146
147
        return $msgMock;
148
    }
149
}
150