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(), []); |
|
|
|
|
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(), []); |
|
|
|
|
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(), []); |
|
|
|
|
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
|
|
|
|
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.