Completed
Push — master ( e9401f...2161bf )
by Daniel
03:27
created

SubscriberBuilderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 71
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetConnectionManager() 10 10 1
A testBuildQueue() 11 11 1
A getAMQPStreamConnectionMock() 18 18 1
A getConnectionManagerMock() 8 8 1
A getQueueServiceMock() 8 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\Subscriber;
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\Subscriber\SubscriberBuilder;
13
use Cmobi\RabbitmqBundle\Transport\Subscriber\SubscriberQueueBag;
14
15 View Code Duplication
class SubscriberBuilderTest extends BaseTestCase
0 ignored issues
show
Duplication introduced by
This class 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...
16
{
17
    public function testGetConnectionManager()
18
    {
19
        $subscriberBuilder = new SubscriberBuilder(
20
            $this->getConnectionManagerMock(),
21
            $this->getLoggerMock(), []
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
22
        );
23
        $connectionManager = $subscriberBuilder->getConnectionManager();
24
25
        $this->assertInstanceOf(ConnectionManager::class, $connectionManager);
26
    }
27
28
    public function testBuildQueue()
29
    {
30
        $subscriberBuilder = new SubscriberBuilder(
31
            $this->getConnectionManagerMock(),
32
            $this->getLoggerMock()
33
        );
34
        $subscriberQueueBag = new SubscriberQueueBag('test_exchange');
35
        $queue = $subscriberBuilder->buildQueue('test', $this->getQueueServiceMock(), $subscriberQueueBag);
36
37
        $this->assertInstanceOf(QueueInterface::class, $queue);
38
    }
39
40
    /**
41
     * @return CmobiAMQPConnectionInterface
42
     */
43
    protected function getAMQPStreamConnectionMock()
44
    {
45
        $class = $this->getMockBuilder(CmobiAMQPConnection::class)
46
            ->disableOriginalConstructor()
47
            ->getMock();
48
49
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
50
            ->disableOriginalConstructor()
51
            ->getMock();
52
        $channelMock->expects($this->any())
53
            ->method('basic_qos')
54
            ->willReturn(true);
55
56
        $class->method('channel')
57
            ->willReturn($channelMock);
58
59
        return $class;
60
    }
61
62
    /**
63
     * @return ConnectionManager
64
     */
65
    protected function getConnectionManagerMock()
66
    {
67
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
68
            ->disableOriginalConstructor()
69
            ->getMock();
70
71
        return $connectionManagerMock;
72
    }
73
74
    /**
75
     * @return QueueServiceInterface
76
     */
77
    protected function getQueueServiceMock()
78
    {
79
        $queueCallback = $this->getMockBuilder(QueueServiceInterface::class)
80
            ->disableOriginalConstructor()
81
            ->getMock();
82
83
        return $queueCallback;
84
    }
85
}
86