RpcServerBuilderTest::getConnectionManagerMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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