Completed
Push — master ( 248a24...bb02de )
by Daniel
02:42
created

getAMQPStreamConnectionMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Tests\Transport\PubSub;
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\PubSub\ExchangeType;
13
use Cmobi\RabbitmqBundle\Transport\PubSub\SubscriberBuilder;
14
use Cmobi\RabbitmqBundle\Transport\PubSub\SubscriberQueueBag;
15
16 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...
17
{
18
    public function testGetConnectionManager()
19
    {
20
        $subscriberBuilder = new SubscriberBuilder(
21
            $this->getConnectionManagerMock(),
22
            $this->getLoggerMock(), []
0 ignored issues
show
Unused Code introduced by
The call to SubscriberBuilder::__construct() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

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