SubscriberBuilderTest::getConnectionManagerMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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
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...
Documentation introduced by
$this->getLoggerMock() is of type object<Psr\Log\LoggerInterface>, 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()
0 ignored issues
show
Documentation introduced by
$this->getLoggerMock() is of type object<Psr\Log\LoggerInterface>, 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...
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