QueueTest::testGetQueueBag()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Tests\Queue;
4
5
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel;
6
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
7
use Cmobi\RabbitmqBundle\Queue\Queue;
8
use Cmobi\RabbitmqBundle\Queue\QueueBagInterface;
9
use Cmobi\RabbitmqBundle\Queue\QueueCallbackInterface;
10
use Cmobi\RabbitmqBundle\Tests\BaseTestCase;
11
12
class QueueTest extends BaseTestCase
13
{
14
    public function testGetQueueBag()
15
    {
16
        $queue = new Queue($this->getConnectionManagerMock(), $this->getQueueBagMock(), $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...
17
18
        $this->assertInstanceOf(QueueBagInterface::class, $queue->getQueuebag());
19
    }
20
21
    public function testGetCallback()
22
    {
23
        $queue = new Queue($this->getConnectionManagerMock(), $this->getQueueBagMock(), $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...
24
        $queue->setCallback($this->getQueueCallbackMock());
25
26
        $callback = $queue->getCallback();
27
28
        $this->assertInstanceOf(QueueCallbackInterface::class, $callback);
29
    }
30
31
    /**
32
     * @return QueueBagInterface
33
     */
34
    protected function getQueueBagMock()
35
    {
36
        $bagMock = $this->getMockBuilder(QueueBagInterface::class)
37
            ->disableOriginalConstructor()
38
            ->getMock();
39
40
        return $bagMock;
41
    }
42
43
    /**
44
     * @return CmobiAMQPChannel
45
     */
46
    protected function getCmobiAMQPChannelMock()
47
    {
48
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
49
            ->disableOriginalConstructor()
50
            ->getMock();
51
        $channelMock->expects($this->any())
52
            ->method('basic_qos')
53
            ->willReturn(true);
54
55
        return $channelMock;
56
    }
57
58
    /**
59
     * @return ConnectionManager
60
     */
61
    protected function getConnectionManagerMock()
62
    {
63
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
64
            ->disableOriginalConstructor()
65
            ->getMock();
66
67
        return $connectionManagerMock;
68
    }
69
70
    /**
71
     * @return QueueCallbackInterface
72
     */
73
    protected function getQueueCallbackMock()
74
    {
75
        $callbackMock = $this->getMockBuilder(QueueCallbackInterface::class)
76
            ->disableOriginalConstructor()
77
            ->getMock();
78
        $callbackMock->method('toClosure')
79
            ->willReturn(function () {});
80
81
        return $callbackMock;
82
    }
83
}
84