From 3f95717a8e8396e255942299ea3c266731e1e090 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Wed, 13 Sep 2017 09:14:37 +0300 Subject: [PATCH] [bundle] add tests for the case where topic subscriber does not def processor name --- .../Compiler/BuildClientRoutingPassTest.php | 25 +++++++++++++++++++ .../BuildProcessorRegistryPassTest.php | 23 +++++++++++++++++ .../WithoutProcessorNameTopicSubscriber.php | 18 +++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/Mock/WithoutProcessorNameTopicSubscriber.php diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildClientRoutingPassTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildClientRoutingPassTest.php index a4b769c02..d553d53f0 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildClientRoutingPassTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildClientRoutingPassTest.php @@ -9,6 +9,7 @@ use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\ProcessorNameCommandSubscriber; use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\ProcessorNameTopicSubscriber; use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\QueueNameTopicSubscriber; +use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\WithoutProcessorNameTopicSubscriber; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -213,6 +214,30 @@ public function testShouldBuildRouteFromSubscriberIfQueueNameSpecified() $this->assertEquals($expectedRoutes, $router->getArgument(1)); } + public function testShouldBuildRouteFromWithoutProcessorNameTopicSubscriber() + { + $container = $this->createContainerBuilder(); + + $processor = new Definition(WithoutProcessorNameTopicSubscriber::class); + $processor->addTag('enqueue.client.processor'); + $container->setDefinition('processor-service-id', $processor); + + $router = new Definition(); + $router->setArguments([null, null, null]); + $container->setDefinition('enqueue.client.router_processor', $router); + + $pass = new BuildClientRoutingPass(); + $pass->process($container); + + $expectedRoutes = [ + 'without-processor-name' => [ + ['processor-service-id', 'a_queue_name'], + ], + ]; + + $this->assertEquals($expectedRoutes, $router->getArgument(1)); + } + public function testShouldThrowExceptionWhenTopicSubscriberConfigurationIsInvalid() { $container = $this->createContainerBuilder(); diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildProcessorRegistryPassTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildProcessorRegistryPassTest.php index 0ad3d3483..c84a5aeba 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildProcessorRegistryPassTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/BuildProcessorRegistryPassTest.php @@ -10,6 +10,7 @@ use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\OnlyTopicNameTopicSubscriber; use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\ProcessorNameCommandSubscriber; use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\ProcessorNameTopicSubscriber; +use Enqueue\Bundle\Tests\Unit\DependencyInjection\Compiler\Mock\WithoutProcessorNameTopicSubscriber; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -132,6 +133,28 @@ public function testShouldBuildRouteFromSubscriberIfOnlyTopicNameSpecified() $this->assertEquals($expectedValue, $processorRegistry->getArgument(0)); } + public function testShouldBuildRouteFromWithoutProcessorNameTopicSubscriber() + { + $container = $this->createContainerBuilder(); + + $processor = new Definition(WithoutProcessorNameTopicSubscriber::class); + $processor->addTag('enqueue.client.processor'); + $container->setDefinition('processor-id', $processor); + + $processorRegistry = new Definition(); + $processorRegistry->setArguments([]); + $container->setDefinition('enqueue.client.processor_registry', $processorRegistry); + + $pass = new BuildProcessorRegistryPass(); + $pass->process($container); + + $expectedValue = [ + 'processor-id' => 'processor-id', + ]; + + $this->assertEquals($expectedValue, $processorRegistry->getArgument(0)); + } + public function testShouldBuildRouteFromSubscriberIfProcessorNameSpecified() { $container = $this->createContainerBuilder(); diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/Mock/WithoutProcessorNameTopicSubscriber.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/Mock/WithoutProcessorNameTopicSubscriber.php new file mode 100644 index 000000000..fa30d9f78 --- /dev/null +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/Compiler/Mock/WithoutProcessorNameTopicSubscriber.php @@ -0,0 +1,18 @@ + [ + 'queueName' => 'a_queue_name', + 'queueNameHardcoded' => true, + ], + ]; + } +}