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()); |
|
|
|
|
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()); |
|
|
|
|
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
|
|
|
|
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: