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