Skip to content

Commit 09bbfdb

Browse files
committed
[client] migrate passes.
1 parent a230cf4 commit 09bbfdb

File tree

4 files changed

+49
-35
lines changed

4 files changed

+49
-35
lines changed

pkg/enqueue-bundle/EnqueueBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function build(ContainerBuilder $container): void
3232
$container->addCompilerPass(new BuildClientTopicSubscriberRoutesPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);
3333
$container->addCompilerPass(new BuildClientCommandSubscriberRoutesPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);
3434
$container->addCompilerPass(new BuildClientProcessorRoutesPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);
35-
$container->addCompilerPass(new AnalyzeRouteCollectionPass('default'), PassConfig::TYPE_BEFORE_OPTIMIZATION, 30);
35+
$container->addCompilerPass(new AnalyzeRouteCollectionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 30);
3636
$container->addCompilerPass(new BuildClientProcessorRegistryPass());
3737

3838
if (class_exists(AsyncEventDispatcherExtension::class)) {

pkg/enqueue/Symfony/Client/DependencyInjection/AnalyzeRouteCollectionPass.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,35 @@
88

99
final class AnalyzeRouteCollectionPass implements CompilerPassInterface
1010
{
11-
/**
12-
* @var string
13-
*/
14-
private $name;
11+
use FormatClientNameTrait;
1512

16-
public function __construct(string $clientName)
17-
{
18-
if (empty($clientName)) {
19-
throw new \InvalidArgumentException('The name could not be empty.');
20-
}
21-
22-
$this->name = $clientName;
23-
}
13+
protected $name;
2414

2515
public function process(ContainerBuilder $container): void
2616
{
27-
$routeCollectionId = sprintf('enqueue.client.%s.route_collection', $this->name);
28-
if (false == $container->hasDefinition($routeCollectionId)) {
29-
return;
17+
if (false == $container->hasParameter('enqueue.clients')) {
18+
throw new \LogicException('The "enqueue.clients" parameter must be set.');
3019
}
3120

32-
$collection = RouteCollection::fromArray($container->getDefinition($routeCollectionId)->getArgument(0));
21+
$names = $container->getParameter('enqueue.clients');
22+
23+
foreach ($names as $name) {
24+
$this->name = $name;
25+
$routeCollectionId = $this->format('route_collection');
26+
if (false == $container->hasDefinition($routeCollectionId)) {
27+
throw new \LogicException(sprintf('Service "%s" not found', $routeCollectionId));
28+
}
3329

34-
$this->exclusiveCommandsCouldNotBeRunOnDefaultQueue($collection);
35-
$this->exclusiveCommandProcessorMustBeSingleOnGivenQueue($collection);
30+
$collection = RouteCollection::fromArray($container->getDefinition($routeCollectionId)->getArgument(0));
31+
32+
$this->exclusiveCommandsCouldNotBeRunOnDefaultQueue($collection);
33+
$this->exclusiveCommandProcessorMustBeSingleOnGivenQueue($collection);
34+
}
35+
}
36+
37+
protected function getName(): string
38+
{
39+
return $this->name;
3640
}
3741

3842
private function exclusiveCommandsCouldNotBeRunOnDefaultQueue(RouteCollection $collection)

pkg/enqueue/Symfony/DependencyInjection/TransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function buildQueueConsumer(ContainerBuilder $container, array $config):
182182
->addArgument(new Reference($this->format('consumption_extensions')))
183183
->addArgument([])
184184
->addArgument(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE))
185-
->addArgument($this->format('receive_timeout', true))
185+
->addArgument($this->parameter('receive_timeout'))
186186
;
187187

188188
$container->register($this->format('processor_registry'), ContainerProcessorRegistry::class);

pkg/enqueue/Tests/Symfony/Client/DependencyInjection/AnalyzeRouteCollectionPassTest.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,36 @@ public function testShouldBeFinal()
2323
$this->assertClassFinal(AnalyzeRouteCollectionPass::class);
2424
}
2525

26-
public function testCouldBeConstructedWithName()
26+
public function testCouldBeConstructedWithoutArguments()
2727
{
28-
$pass = new AnalyzeRouteCollectionPass('aName');
29-
30-
$this->assertAttributeSame('aName', 'name', $pass);
28+
new AnalyzeRouteCollectionPass();
3129
}
3230

33-
public function testThrowIfNameEmptyOnConstruct()
31+
public function testThrowIfEnqueueClientsParameterNotSet()
3432
{
35-
$this->expectException(\InvalidArgumentException::class);
36-
$this->expectExceptionMessage('The name could not be empty.');
37-
new AnalyzeRouteCollectionPass('');
33+
$pass = new AnalyzeRouteCollectionPass();
34+
35+
$this->expectException(\LogicException::class);
36+
$this->expectExceptionMessage('The "enqueue.clients" parameter must be set.');
37+
$pass->process(new ContainerBuilder());
3838
}
3939

40-
public function testShouldDoNothingIfRouteCollectionServiceIsNotRegistered()
40+
public function testThrowsIfNoRouteCollectionServiceFoundForConfiguredTransport()
4141
{
42-
$pass = new AnalyzeRouteCollectionPass('aName');
43-
$pass->process(new ContainerBuilder());
42+
$container = new ContainerBuilder();
43+
$container->setParameter('enqueue.clients', ['foo', 'bar']);
44+
45+
$pass = new AnalyzeRouteCollectionPass();
46+
47+
$this->expectException(\LogicException::class);
48+
$this->expectExceptionMessage('Service "enqueue.client.foo.route_collection" not found');
49+
$pass->process($container);
4450
}
4551

4652
public function testThrowIfExclusiveCommandProcessorOnDefaultQueue()
4753
{
4854
$container = new ContainerBuilder();
55+
$container->setParameter('enqueue.clients', ['aName']);
4956
$container->register('enqueue.client.aName.route_collection')->addArgument([
5057
(new Route(
5158
'aCommand',
@@ -57,14 +64,15 @@ public function testThrowIfExclusiveCommandProcessorOnDefaultQueue()
5764

5865
$this->expectException(\LogicException::class);
5966
$this->expectExceptionMessage('The command "aCommand" processor "aBarProcessor" is exclusive but queue is not specified. Exclusive processors could not be run on a default queue.');
60-
$pass = new AnalyzeRouteCollectionPass('aName');
67+
$pass = new AnalyzeRouteCollectionPass();
6168

6269
$pass->process($container);
6370
}
6471

6572
public function testThrowIfTwoExclusiveCommandProcessorsWorkOnSamePrefixedQueue()
6673
{
6774
$container = new ContainerBuilder();
75+
$container->setParameter('enqueue.clients', ['aName']);
6876
$container->register('enqueue.client.aName.route_collection')->addArgument([
6977
(new Route(
7078
'aFooCommand',
@@ -83,14 +91,15 @@ public function testThrowIfTwoExclusiveCommandProcessorsWorkOnSamePrefixedQueue(
8391

8492
$this->expectException(\LogicException::class);
8593
$this->expectExceptionMessage('The command "aBarCommand" processor "aBarProcessor" is exclusive. The queue "aQueue" already has another exclusive command processor "aFooProcessor" bound to it.');
86-
$pass = new AnalyzeRouteCollectionPass('aName');
94+
$pass = new AnalyzeRouteCollectionPass();
8795

8896
$pass->process($container);
8997
}
9098

9199
public function testThrowIfTwoExclusiveCommandProcessorsWorkOnSameQueue()
92100
{
93101
$container = new ContainerBuilder();
102+
$container->setParameter('enqueue.clients', ['aName']);
94103
$container->register('enqueue.client.aName.route_collection')->addArgument([
95104
(new Route(
96105
'aFooCommand',
@@ -109,14 +118,15 @@ public function testThrowIfTwoExclusiveCommandProcessorsWorkOnSameQueue()
109118

110119
$this->expectException(\LogicException::class);
111120
$this->expectExceptionMessage('The command "aBarCommand" processor "aBarProcessor" is exclusive. The queue "aQueue" already has another exclusive command processor "aFooProcessor" bound to it.');
112-
$pass = new AnalyzeRouteCollectionPass('aName');
121+
$pass = new AnalyzeRouteCollectionPass();
113122

114123
$pass->process($container);
115124
}
116125

117126
public function testShouldNotThrowIfTwoExclusiveCommandProcessorsWorkOnQueueWithSameNameButOnePrefixed()
118127
{
119128
$container = new ContainerBuilder();
129+
$container->setParameter('enqueue.clients', ['aName']);
120130
$container->register('enqueue.client.aName.route_collection')->addArgument([
121131
(new Route(
122132
'aFooCommand',
@@ -133,7 +143,7 @@ public function testShouldNotThrowIfTwoExclusiveCommandProcessorsWorkOnQueueWith
133143
))->toArray(),
134144
]);
135145

136-
$pass = new AnalyzeRouteCollectionPass('aName');
146+
$pass = new AnalyzeRouteCollectionPass();
137147

138148
$pass->process($container);
139149
}

0 commit comments

Comments
 (0)