1 | <?php |
||
29 | class AMQPBackendTest extends TestCase |
||
30 | { |
||
31 | const EXCHANGE = 'exchange'; |
||
32 | const QUEUE = 'foo'; |
||
33 | const KEY = 'message.type.foo'; |
||
34 | const DEAD_LETTER_EXCHANGE = 'dlx'; |
||
35 | const DEAD_LETTER_ROUTING_KEY = 'message.type.dl'; |
||
36 | const TTL = 60000; |
||
37 | const PREFETCH_COUNT = 1; |
||
38 | |||
39 | protected function setUp() |
||
40 | { |
||
41 | if (!class_exists(AmqpConnectionFactory::class)) { |
||
42 | $this->markTestSkipped('enqueue/amqp-lib library is not installed'); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | public function testInitializeWithNoDeadLetterExchangeAndNoDeadLetterRoutingKey() |
||
47 | { |
||
48 | /** |
||
49 | * @var AMQPBackend |
||
50 | * @var AmqpContext|\PHPUnit_Framework_MockObject_MockObject $contextMock |
||
51 | */ |
||
52 | list($backend, $contextMock) = $this->getBackendAndContextMock(); |
||
53 | |||
54 | $queue = new ImplAmqpQueue(self::QUEUE); |
||
55 | $topic = new ImplAmqpTopic(self::EXCHANGE); |
||
56 | |||
57 | $contextMock->expects($this->once()) |
||
|
|||
58 | ->method('createQueue') |
||
59 | ->with($this->identicalTo(self::QUEUE)) |
||
60 | ->willReturn($queue); |
||
61 | |||
62 | $contextMock->expects($this->once()) |
||
63 | ->method('declareQueue') |
||
64 | ->with($this->identicalTo($queue)) |
||
65 | ->willReturnCallback(function (AmqpQueue $queue) { |
||
66 | $this->assertTrue((bool) ($queue->getFlags() & AmqpQueue::FLAG_DURABLE)); |
||
67 | $this->assertSame([], $queue->getArguments()); |
||
68 | }); |
||
69 | |||
70 | $contextMock->expects($this->once()) |
||
71 | ->method('createTopic') |
||
72 | ->with($this->identicalTo(self::EXCHANGE)) |
||
73 | ->willReturn($topic); |
||
74 | |||
75 | $contextMock->expects($this->once()) |
||
76 | ->method('declareTopic') |
||
77 | ->with($this->identicalTo($topic)) |
||
78 | ->willReturnCallback(function (AmqpTopic $topic) { |
||
79 | $this->assertTrue((bool) ($topic->getFlags() & AmqpTopic::FLAG_DURABLE)); |
||
80 | $this->assertSame(AmqpTopic::TYPE_DIRECT, $topic->getType()); |
||
81 | $this->assertSame([], $topic->getArguments()); |
||
82 | }); |
||
83 | |||
84 | $contextMock->expects($this->once()) |
||
85 | ->method('bind') |
||
86 | ->with($this->isInstanceOf(AmqpBind::class)) |
||
87 | ->willReturnCallback(function (ImplAmqpBind $bind) use ($queue, $topic) { |
||
88 | $this->assertSame($queue, $bind->getTarget()); |
||
89 | $this->assertSame($topic, $bind->getSource()); |
||
90 | $this->assertSame(self::KEY, $bind->getRoutingKey()); |
||
91 | }); |
||
92 | |||
93 | $backend->initialize(); |
||
94 | } |
||
95 | |||
96 | public function testInitializeWithDeadLetterExchangeAndNoDeadLetterRoutingKey() |
||
97 | { |
||
98 | /** |
||
99 | * @var AMQPBackend |
||
100 | * @var AmqpContext|\PHPUnit_Framework_MockObject_MockObject $contextMock |
||
101 | */ |
||
102 | list($backend, $contextMock) = $this->getBackendAndContextMock(false, self::DEAD_LETTER_EXCHANGE); |
||
103 | |||
104 | $queue = new ImplAmqpQueue(self::QUEUE); |
||
105 | $topic = new ImplAmqpTopic(self::EXCHANGE); |
||
106 | $deadLetterTopic = new ImplAmqpTopic(self::DEAD_LETTER_EXCHANGE); |
||
107 | |||
108 | $contextMock->expects($this->at(0)) |
||
109 | ->method('createQueue') |
||
110 | ->with($this->identicalTo(self::QUEUE)) |
||
111 | ->willReturn($queue); |
||
112 | |||
113 | $contextMock->expects($this->at(1)) |
||
114 | ->method('declareQueue') |
||
115 | ->with($this->identicalTo($queue)) |
||
116 | ->willReturnCallback(function (AmqpQueue $queue) { |
||
117 | $this->assertTrue((bool) ($queue->getFlags() & AmqpQueue::FLAG_DURABLE)); |
||
118 | $this->assertSame(['x-dead-letter-exchange' => self::DEAD_LETTER_EXCHANGE], $queue->getArguments()); |
||
119 | }); |
||
120 | |||
121 | $contextMock->expects($this->at(2)) |
||
122 | ->method('createTopic') |
||
123 | ->with($this->identicalTo(self::EXCHANGE)) |
||
124 | ->willReturn($topic); |
||
125 | |||
126 | $contextMock->expects($this->at(3)) |
||
127 | ->method('declareTopic') |
||
128 | ->with($this->identicalTo($topic)); |
||
129 | |||
130 | $contextMock->expects($this->at(4)) |
||
131 | ->method('bind') |
||
132 | ->with($this->isInstanceOf(AmqpBind::class)); |
||
133 | |||
134 | $contextMock->expects($this->at(5)) |
||
135 | ->method('createTopic') |
||
136 | ->with($this->identicalTo(self::DEAD_LETTER_EXCHANGE)) |
||
137 | ->willReturn($deadLetterTopic); |
||
138 | |||
139 | $contextMock->expects($this->at(6)) |
||
140 | ->method('declareTopic') |
||
141 | ->with($this->identicalTo($deadLetterTopic)) |
||
142 | ->willReturnCallback(function (AmqpTopic $topic) { |
||
143 | $this->assertTrue((bool) ($topic->getFlags() & AmqpTopic::FLAG_DURABLE)); |
||
144 | $this->assertSame(AmqpTopic::TYPE_DIRECT, $topic->getType()); |
||
145 | $this->assertSame([], $topic->getArguments()); |
||
146 | }); |
||
147 | |||
148 | $backend->initialize(); |
||
149 | } |
||
150 | |||
151 | // |
||
152 | public function testInitializeWithDeadLetterExchangeAndDeadLetterRoutingKey() |
||
198 | |||
199 | public function testInitializeWithTTL() |
||
238 | |||
239 | public function testGetIteratorWithNoPrefetchCount() |
||
240 | { |
||
241 | /** |
||
242 | * @var AMQPBackend |
||
243 | * @var AmqpContext|\PHPUnit_Framework_MockObject_MockObject $contextMock |
||
244 | */ |
||
245 | list($backend, $contextMock) = $this->getBackendAndContextMock(); |
||
246 | |||
247 | $queue = new ImplAmqpQueue('aQueue'); |
||
248 | $consumerMock = $this->createMock(AmqpConsumer::class); |
||
249 | $consumerMock->expects($this->once()) |
||
250 | ->method('getQueue') |
||
251 | ->willReturn($queue); |
||
252 | |||
253 | $contextMock->expects($this->never()) |
||
254 | ->method('setQos'); |
||
255 | |||
256 | $contextMock->expects($this->once()) |
||
257 | ->method('createQueue') |
||
258 | ->willReturn($queue); |
||
259 | |||
260 | $contextMock->expects($this->once()) |
||
261 | ->method('createConsumer') |
||
262 | ->with($this->identicalTo($queue)) |
||
263 | ->willReturn($consumerMock); |
||
264 | |||
265 | $iterator = $backend->getIterator(); |
||
266 | |||
267 | $this->assertInstanceOf(AMQPMessageIterator::class, $iterator); |
||
268 | } |
||
269 | |||
270 | public function testGetIteratorWithPrefetchCount() |
||
301 | |||
302 | protected function getBackendAndContextMock($recover = false, $deadLetterExchange = null, $deadLetterRoutingKey = null, $ttl = null, $prefetchCount = null) |
||
303 | { |
||
304 | $backend = new AMQPBackend( |
||
305 | self::EXCHANGE, |
||
349 | } |
||
350 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.