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

WorkerBuilderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 32
loc 64
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetConnectionManager() 7 7 1
A testBuildQueue() 7 7 1
A getAMQPStreamConnectionMock() 18 18 1
A getConnectionManagerMock() 0 8 1
A getQueueServiceMock() 0 8 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\Rpc;
4
5
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel;
6
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnection;
7
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnectionInterface;
8
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
9
use Cmobi\RabbitmqBundle\Queue\QueueInterface;
10
use Cmobi\RabbitmqBundle\Queue\QueueServiceInterface;
11
use Cmobi\RabbitmqBundle\Tests\BaseTestCase;
12
use Cmobi\RabbitmqBundle\Transport\Worker\WorkerBuilder;
13
14
class WorkerBuilderTest extends BaseTestCase
15
{
16 View Code Duplication
    public function testGetConnectionManager()
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...
17
    {
18
        $workerServer = new WorkerBuilder($this->getConnectionManagerMock(), $this->getLoggerMock(), []);
19
        $connectionManager = $workerServer->getConnectionManager();
20
21
        $this->assertInstanceOf(ConnectionManager::class, $connectionManager);
22
    }
23
24 View Code Duplication
    public function testBuildQueue()
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...
25
    {
26
        $workerServer = new WorkerBuilder($this->getConnectionManagerMock(), $this->getLoggerMock(), []);
27
        $queue = $workerServer->buildQueue('test', $this->getQueueServiceMock());
28
29
        $this->assertInstanceOf(QueueInterface::class, $queue);
30
    }
31
32
    /**
33
     * @return CmobiAMQPConnectionInterface
34
     */
35 View Code Duplication
    protected function getAMQPStreamConnectionMock()
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...
36
    {
37
        $class = $this->getMockBuilder(CmobiAMQPConnection::class)
38
            ->disableOriginalConstructor()
39
            ->getMock();
40
41
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
42
            ->disableOriginalConstructor()
43
            ->getMock();
44
        $channelMock->expects($this->any())
45
            ->method('basic_qos')
46
            ->willReturn(true);
47
48
        $class->method('channel')
49
            ->willReturn($channelMock);
50
51
        return $class;
52
    }
53
54
    /**
55
     * @return ConnectionManager
56
     */
57
    protected function getConnectionManagerMock()
58
    {
59
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
60
            ->disableOriginalConstructor()
61
            ->getMock();
62
63
        return $connectionManagerMock;
64
    }
65
66
    /**
67
     * @return QueueServiceInterface
68
     */
69
    protected function getQueueServiceMock()
70
    {
71
        $queueCallback = $this->getMockBuilder(QueueServiceInterface::class)
72
            ->disableOriginalConstructor()
73
            ->getMock();
74
75
        return $queueCallback;
76
    }
77
}
78