diff --git a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php index 3506cba4..ff09dcc8 100644 --- a/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php +++ b/src/Symfony/DependencyInjection/Compiler/PresenterCompilerPass.php @@ -20,6 +20,13 @@ final class PresenterCompilerPass implements CompilerPassInterface foreach ($container->findTaggedServiceIds('flasher.presenter') as $id => $tags) { foreach ($tags as $attributes) { + if (!isset($attributes['alias'])) { + throw new \InvalidArgumentException(\sprintf( + 'Service "%s" tagged with "flasher.presenter" must have an "alias" attribute.', + $id + )); + } + $definition->addMethodCall('addPresenter', [ $attributes['alias'], new ServiceClosureArgument(new Reference($id)), diff --git a/tests/Symfony/DependencyInjection/Compiler/PresenterCompilerPassTest.php b/tests/Symfony/DependencyInjection/Compiler/PresenterCompilerPassTest.php index ef7141b6..a0067efd 100644 --- a/tests/Symfony/DependencyInjection/Compiler/PresenterCompilerPassTest.php +++ b/tests/Symfony/DependencyInjection/Compiler/PresenterCompilerPassTest.php @@ -54,4 +54,18 @@ final class PresenterCompilerPassTest extends TestCase $this->assertCount(0, $definition->getMethodCalls(), 'No method calls should be made when no tagged services exist.'); } + + public function testProcessThrowsExceptionWhenAliasIsMissing(): void + { + $definition = new Definition(); + $this->container->setDefinition('flasher.response_manager', $definition); + + // Register a service without the required 'alias' attribute + $this->container->register('presenter_without_alias')->addTag('flasher.presenter'); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Service "presenter_without_alias" tagged with "flasher.presenter" must have an "alias" attribute.'); + + $this->compilerPass->process($this->container); + } }