1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\Tests\RabbitMq; |
4
|
|
|
|
5
|
|
|
use OldSound\RabbitMqBundle\Provider\QueueOptionsProviderInterface; |
6
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\Consumer; |
7
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\DynamicConsumer; |
8
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
9
|
|
|
use PhpAmqpLib\Connection\AMQPConnection; |
10
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
11
|
|
|
|
12
|
|
|
class DynamicConsumerTest extends ConsumerTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @return DynamicConsumer |
16
|
|
|
*/ |
17
|
|
|
public function getConsumer(AMQPConnection $amqpConnection, AMQPChannel $amqpChannel) |
18
|
|
|
{ |
19
|
|
|
return new DynamicConsumer($amqpConnection, $amqpChannel); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Preparing QueueOptionsProviderInterface instance |
24
|
|
|
* |
25
|
|
|
* @return MockObject|QueueOptionsProviderInterface |
26
|
|
|
*/ |
27
|
|
|
private function prepareQueueOptionsProvider() |
28
|
|
|
{ |
29
|
|
|
return $this->getMockBuilder('\OldSound\RabbitMqBundle\Provider\QueueOptionsProviderInterface') |
30
|
|
|
->getMock(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testQueueOptionsProvider(): void |
34
|
|
|
{ |
35
|
|
|
$amqpConnection = $this->prepareAMQPConnection(); |
36
|
|
|
$amqpChannel = $this->prepareAMQPChannel(); |
37
|
|
|
$consumer = $this->getConsumer($amqpConnection, $amqpChannel); |
38
|
|
|
$consumer->setContext('foo'); |
39
|
|
|
|
40
|
|
|
$queueOptionsProvider = $this->prepareQueueOptionsProvider(); |
41
|
|
|
$queueOptionsProvider->expects($this->once()) |
42
|
|
|
->method('getQueueOptions') |
43
|
|
|
->will($this->returnValue( |
44
|
|
|
array( |
45
|
|
|
'name' => 'queue_foo', |
46
|
|
|
'routing_keys' => array( |
47
|
|
|
'foo.*' |
48
|
|
|
) |
49
|
|
|
) |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
$consumer->setQueueOptionsProvider($queueOptionsProvider); |
53
|
|
|
|
54
|
|
|
$reflectionClass = new \ReflectionClass(get_class($consumer)); |
55
|
|
|
$reflectionMethod = $reflectionClass->getMethod('mergeQueueOptions'); |
56
|
|
|
$reflectionMethod->setAccessible(true); |
57
|
|
|
$reflectionMethod->invoke($consumer); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|