Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip registering controllers as a services if there is no custom class defined #297

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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],
],
]
);
Expand Down