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
|
|
|
public function getConsumer(AMQPConnection $amqpConnection, AMQPChannel $amqpChannel): DynamicConsumer |
15
|
|
|
{ |
16
|
|
|
return new DynamicConsumer($amqpConnection, $amqpChannel); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Preparing QueueOptionsProviderInterface instance |
21
|
|
|
* |
22
|
|
|
* @return MockObject|QueueOptionsProviderInterface |
23
|
|
|
*/ |
24
|
|
|
private function prepareQueueOptionsProvider() |
25
|
|
|
{ |
26
|
|
|
return $this->getMockBuilder('\OldSound\RabbitMqBundle\Provider\QueueOptionsProviderInterface') |
27
|
|
|
->getMock(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testQueueOptionsProvider(): void |
31
|
|
|
{ |
32
|
|
|
$amqpConnection = $this->prepareAMQPConnection(); |
33
|
|
|
$amqpChannel = $this->prepareAMQPChannel(); |
34
|
|
|
$consumer = $this->getConsumer($amqpConnection, $amqpChannel); |
35
|
|
|
$consumer->setContext('foo'); |
36
|
|
|
|
37
|
|
|
$queueOptionsProvider = $this->prepareQueueOptionsProvider(); |
38
|
|
|
$queueOptionsProvider->expects($this->once()) |
39
|
|
|
->method('getQueueOptions') |
40
|
|
|
->will($this->returnValue( |
41
|
|
|
array( |
42
|
|
|
'name' => 'queue_foo', |
43
|
|
|
'routing_keys' => array( |
44
|
|
|
'foo.*' |
45
|
|
|
) |
46
|
|
|
) |
47
|
|
|
)); |
48
|
|
|
|
49
|
|
|
$consumer->setQueueOptionsProvider($queueOptionsProvider); |
50
|
|
|
|
51
|
|
|
$reflectionClass = new \ReflectionClass(get_class($consumer)); |
52
|
|
|
$reflectionMethod = $reflectionClass->getMethod('mergeQueueOptions'); |
53
|
|
|
$reflectionMethod->setAccessible(true); |
54
|
|
|
$reflectionMethod->invoke($consumer); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|