|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace OldSound\RabbitMqBundle\Tests\Command; |
|
6
|
|
|
|
|
7
|
|
|
use OldSound\RabbitMqBundle\Command\SetupFabricCommand; |
|
8
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\AmqpPartsHolder; |
|
9
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\AnonConsumer; |
|
10
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\BatchConsumer; |
|
11
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\Consumer; |
|
12
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\DynamicConsumer; |
|
13
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\MultipleConsumer; |
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @covers \OldSound\RabbitMqBundle\Command\SetupFabricCommand |
|
21
|
|
|
*/ |
|
22
|
|
|
class SetupFabricCommandTest extends KernelTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function testExecute(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$application = $this->createApplication(); |
|
27
|
|
|
|
|
28
|
|
|
$command = new SetupFabricCommand(); |
|
29
|
|
|
$container = $application->getKernel()->getContainer(); |
|
30
|
|
|
|
|
31
|
|
|
$partsHolder = new AmqpPartsHolder(); |
|
32
|
|
|
$consumer = $this->createMock(Consumer::class); |
|
33
|
|
|
$consumer->expects($this->once())->method('setupFabric'); |
|
34
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $consumer); |
|
35
|
|
|
|
|
36
|
|
|
$multipleConsumer = $this->createMock(MultipleConsumer::class); |
|
37
|
|
|
$multipleConsumer->expects($this->once())->method('setupFabric'); |
|
38
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $multipleConsumer); |
|
39
|
|
|
|
|
40
|
|
|
$batchConsumer = $this->createMock(BatchConsumer::class); |
|
41
|
|
|
$batchConsumer->expects($this->once())->method('setupFabric'); |
|
42
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $batchConsumer); |
|
43
|
|
|
|
|
44
|
|
|
$anonConsumer = $this->createMock(AnonConsumer::class); |
|
45
|
|
|
$anonConsumer->expects($this->once())->method('setupFabric'); |
|
46
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $anonConsumer); |
|
47
|
|
|
|
|
48
|
|
|
$dynamicConsumer = $this->createMock(DynamicConsumer::class); |
|
49
|
|
|
$dynamicConsumer->expects($this->never())->method('setupFabric'); |
|
50
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $dynamicConsumer); |
|
51
|
|
|
|
|
52
|
|
|
$container->set('old_sound_rabbit_mq.parts_holder', $partsHolder); |
|
53
|
|
|
|
|
54
|
|
|
$command->setContainer($container); |
|
55
|
|
|
|
|
56
|
|
|
// TODO: Use addCommand() once Symfony Support for < 7.4 is dropped |
|
57
|
|
|
$application->add($command); |
|
58
|
|
|
|
|
59
|
|
|
$registeredCommand = $application->find('rabbitmq:setup-fabric'); |
|
60
|
|
|
|
|
61
|
|
|
$commandTester = new CommandTester($registeredCommand); |
|
62
|
|
|
|
|
63
|
|
|
$commandTester->execute([ |
|
64
|
|
|
'command' => $registeredCommand->getName(), |
|
65
|
|
|
], [ |
|
66
|
|
|
'verbosity' => OutputInterface::VERBOSITY_VERBOSE, |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
self::assertSame(0, $commandTester->getStatusCode()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testExecute_withSkipAnonConsumers(): void |
|
73
|
|
|
{ |
|
74
|
|
|
$application = $this->createApplication(); |
|
75
|
|
|
|
|
76
|
|
|
$command = new SetupFabricCommand(); |
|
77
|
|
|
$container = $application->getKernel()->getContainer(); |
|
78
|
|
|
|
|
79
|
|
|
$partsHolder = new AmqpPartsHolder(); |
|
80
|
|
|
$consumer = $this->createMock(Consumer::class); |
|
81
|
|
|
$consumer->expects($this->once())->method('setupFabric'); |
|
82
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $consumer); |
|
83
|
|
|
|
|
84
|
|
|
$multipleConsumer = $this->createMock(MultipleConsumer::class); |
|
85
|
|
|
$multipleConsumer->expects($this->once())->method('setupFabric'); |
|
86
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $multipleConsumer); |
|
87
|
|
|
|
|
88
|
|
|
$batchConsumer = $this->createMock(BatchConsumer::class); |
|
89
|
|
|
$batchConsumer->expects($this->once())->method('setupFabric'); |
|
90
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $batchConsumer); |
|
91
|
|
|
|
|
92
|
|
|
$anonConsumer = $this->createMock(AnonConsumer::class); |
|
93
|
|
|
$anonConsumer->expects($this->never())->method('setupFabric'); |
|
94
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $anonConsumer); |
|
95
|
|
|
|
|
96
|
|
|
$dynamicConsumer = $this->createMock(DynamicConsumer::class); |
|
97
|
|
|
$dynamicConsumer->expects($this->never())->method('setupFabric'); |
|
98
|
|
|
$partsHolder->addPart('old_sound_rabbit_mq.base_amqp', $dynamicConsumer); |
|
99
|
|
|
|
|
100
|
|
|
$container->set('old_sound_rabbit_mq.parts_holder', $partsHolder); |
|
101
|
|
|
|
|
102
|
|
|
$command->setContainer($container); |
|
103
|
|
|
|
|
104
|
|
|
// TODO: Use addCommand() once Symfony Support for < 7.4 is dropped |
|
105
|
|
|
$application->add($command); |
|
106
|
|
|
|
|
107
|
|
|
$registeredCommand = $application->find('rabbitmq:setup-fabric'); |
|
108
|
|
|
|
|
109
|
|
|
$commandTester = new CommandTester($registeredCommand); |
|
110
|
|
|
|
|
111
|
|
|
$commandTester->execute([ |
|
112
|
|
|
'command' => $registeredCommand->getName(), |
|
113
|
|
|
'--skip-anon-consumers' => true, |
|
114
|
|
|
], [ |
|
115
|
|
|
'verbosity' => OutputInterface::VERBOSITY_VERBOSE, |
|
116
|
|
|
]); |
|
117
|
|
|
|
|
118
|
|
|
self::assertSame(0, $commandTester->getStatusCode()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
private function createApplication(): Application |
|
122
|
|
|
{ |
|
123
|
|
|
$kernel = self::createKernel(); |
|
124
|
|
|
$kernel->boot(); |
|
125
|
|
|
|
|
126
|
|
|
return new Application($kernel); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|