diff --git a/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php b/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php index a8109a88b..189c9e9d9 100644 --- a/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php +++ b/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php @@ -35,6 +35,10 @@ public function process(ContainerBuilder $container): void foreach ($resources as $alias => $configuration) { $metadata = Metadata::fromAliasAndConfiguration($alias, $configuration); + if (!$metadata->hasClass('controller')) { + continue; + } + $this->validateSyliusResource($metadata->getClass('model')); $controllerFqcn = $metadata->getClass('controller'); diff --git a/src/Bundle/Tests/DependencyInjection/Compiler/RegisterFqcnControllersPassTest.php b/src/Bundle/Tests/DependencyInjection/Compiler/RegisterFqcnControllersPassTest.php index d27665dc4..987eb8170 100644 --- a/src/Bundle/Tests/DependencyInjection/Compiler/RegisterFqcnControllersPassTest.php +++ b/src/Bundle/Tests/DependencyInjection/Compiler/RegisterFqcnControllersPassTest.php @@ -46,6 +46,29 @@ public function it_registers_alias_for_resource_controller_as_a_FQCN(): void $this->assertContainerBuilderHasService(BookTestController::class); } + /** + * @test + */ + public function it_skips_the_alias_if_controller_class_is_not_defined(): void + { + $this->setDefinition('sylius.resource_registry', new Definition()); + $this->setDefinition('app.controller.book', new Definition()); + + $this->setParameter( + 'sylius.resources', + [ + 'app.book' => [ + 'driver' => 'doctrine/orm', + 'classes' => ['model' => BookTestClass::class], + ], + ] + ); + + $this->compile(); + + $this->assertContainerBuilderNotHasService(BookTestController::class); + } + /** * @test */ @@ -58,7 +81,7 @@ public function it_throws_exception_if_class_does_not_implement_resource_interfa [ 'app.normalClass' => [ 'driver' => 'doctrine/orm', - 'classes' => ['model' => NormalClass::class], + 'classes' => ['model' => NormalClass::class, 'controller' => BookTestController::class], ], ] );