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

TaskTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 49.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 3
dl 43
loc 87
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetQueueName() 0 6 1
A testGetFromName() 0 6 1
A getConnectionManagerMock() 0 10 1
A getConnectionMock() 14 14 1
A getChannelMock() 15 15 1
A getCmobiAMQPMessage() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Tests\Transport\Worker;
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\Worker\Task;
11
12
class TaskTest extends BaseTestCase
13
{
14
    public function testGetQueueName()
15
    {
16
        $taskClient = new Task('test', $this->getConnectionManagerMock(), 'test');
17
18
        $this->assertEquals('test', $taskClient->getQueueName());
19
    }
20
21
    public function testGetFromName()
22
    {
23
        $taskClient = new Task('test', $this->getConnectionManagerMock(), 'caller_test');
24
25
        $this->assertEquals('caller_test', $taskClient->getFromName());
26
    }
27
28
    /**
29
     * @return ConnectionManager
30
     */
31
    protected function getConnectionManagerMock()
32
    {
33
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
34
            ->disableOriginalConstructor()
35
            ->getMock();
36
        $connectionManagerMock->method('getConnection')
37
            ->willReturn($this->getConnectionMock());
38
39
        return $connectionManagerMock;
40
    }
41
42
    /**
43
     * @return CmobiAMQPConnection
44
     */
45 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...
46
    {
47
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
        $connectionMock->method('isConnected')
51
            ->willReturn(true);
52
        $connectionMock->method('reconnect')
53
            ->willReturn(true);
54
        $connectionMock->method('channel')
55
            ->willReturn($this->getChannelMock());
56
57
        return $connectionMock;
58
    }
59
60
    /**
61
     * @return CmobiAMQPChannel
62
     */
63 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...
64
    {
65
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
        $channelMock
69
            ->expects($this->any())
70
            ->method('basic_publish')
71
            ->willReturn(true);
72
        $channelMock
73
            ->method('basicConsume')
74
            ->willReturn(true);
75
76
        return $channelMock;
77
    }
78
79
    /**
80
     * @param string $msg
81
     * @param null   $correlationId
82
     *
83
     * @return CmobiAMQPMessage
84
     */
85 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...
86
    {
87
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
88
            ->disableOriginalConstructor()
89
            ->getMock();
90
        $msgMock->method('get')
91
            ->willReturn('correlation_id')
92
            ->willReturn($correlationId);
93
        $msgMock->method('getBody')
94
            ->willReturn($msg);
95
96
        return $msgMock;
97
    }
98
}
99