fix: validate alias attribute in PresenterCompilerPass

Add validation to ensure services tagged with 'flasher.presenter' have
the required 'alias' attribute. Previously, accessing $attributes['alias']
without checking would throw an "Undefined array key" error.

Now throws a clear InvalidArgumentException with a helpful message.
This commit is contained in:
Younes ENNAJI
2026-03-01 20:01:12 +00:00
parent 5202c86107
commit fd36c2ec0c
2 changed files with 21 additions and 0 deletions
@@ -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);
}
}