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

RpcServerBuilderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 54.79 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 40
loc 73
rs 10
c 0
b 0
f 0

6 Methods

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