Completed
Pull Request — master (#1)
by Daniel
15:18 queued 11:09
created

TaskTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 52.48 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 53
loc 101
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetQueueName() 0 6 1
A testRefreshChannel() 0 6 1
A testGetChannel() 0 6 1
A testGetFromName() 0 6 1
A getConnectionManagerMock() 10 10 1
A getConnectionMock() 14 14 1
A getCmobiAMQPMessage() 13 13 1
A getChannelMock() 15 15 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());
17
18
        $this->assertEquals('test', $taskClient->getQueueName());
19
    }
20
21
    public function testRefreshChannel()
22
    {
23
        $taskClient = new Task('test', $this->getConnectionManagerMock());
24
25
        $this->assertInstanceOf(CmobiAMQPChannel::class, $taskClient->refreshChannel());
26
    }
27
28
    public function testGetChannel()
29
    {
30
        $taskClient = new Task('test', $this->getConnectionManagerMock());
31
32
        $this->assertInstanceOf(CmobiAMQPChannel::class, $taskClient->refreshChannel());
33
    }
34
35
    public function testGetFromName()
36
    {
37
        $taskClient = new Task('test', $this->getConnectionManagerMock(), 'caller_test');
38
39
        $this->assertEquals('caller_test', $taskClient->getFromName());
40
    }
41
42
    /**
43
     * @return ConnectionManager
44
     */
45 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...
46
    {
47
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
        $connectionManagerMock->method('getConnection')
51
            ->willReturn($this->getConnectionMock());
52
53
        return $connectionManagerMock;
54
    }
55
56
    /**
57
     * @return CmobiAMQPConnection
58
     */
59 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...
60
    {
61
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
62
            ->disableOriginalConstructor()
63
            ->getMock();
64
        $connectionMock->method('isConnected')
65
            ->willReturn(true);
66
        $connectionMock->method('reconnect')
67
            ->willReturn(true);
68
        $connectionMock->method('channel')
69
            ->willReturn($this->getChannelMock());
70
71
        return $connectionMock;
72
    }
73
74
    /**
75
     * @return CmobiAMQPChannel
76
     */
77 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...
78
    {
79
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
80
            ->disableOriginalConstructor()
81
            ->getMock();
82
        $channelMock
83
            ->expects($this->any())
84
            ->method('basic_publish')
85
            ->willReturn(true);
86
        $channelMock
87
            ->method('basicConsume')
88
            ->willReturn(true);
89
90
        return $channelMock;
91
    }
92
93
    /**
94
     * @param string $msg
95
     * @param null   $correlationId
96
     *
97
     * @return CmobiAMQPMessage
98
     */
99 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...
100
    {
101
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
102
            ->disableOriginalConstructor()
103
            ->getMock();
104
        $msgMock->method('get')
105
            ->willReturn('correlation_id')
106
            ->willReturn($correlationId);
107
        $msgMock->method('getBody')
108
            ->willReturn($msg);
109
110
        return $msgMock;
111
    }
112
}
113