public function testGetMessageConfiguration() { $messageConfigurations = ['message_identifier_1' => ['renderer' => 'RendererCode'], 'message_identifier_2' => ['renderer' => 'RendererCode', 'data' => []]]; $expectedMessageConfigurations = ['message_identifier_1' => ['renderer' => 'RendererCode', 'data' => []], 'message_identifier_2' => ['renderer' => 'RendererCode', 'data' => []], 'message_identifier_3' => null]; $pool = new MessageConfigurationsPool($messageConfigurations); foreach ($expectedMessageConfigurations as $messageIdentifier => $expectedConfiguration) { static::assertSame($expectedConfiguration, $pool->getMessageConfiguration($messageIdentifier)); } }
/** * Interpret message * * @param MessageInterface $message * @return string * @throws \LogicException */ public function interpret(MessageInterface $message) { $messageConfiguration = $this->messageConfigurationsPool->getMessageConfiguration($message->getIdentifier()); if (null === $messageConfiguration) { throw new \LogicException(); } $renderer = $this->renderersPool->get($messageConfiguration['renderer']); if (null === $renderer) { throw new \LogicException(); } return $renderer->render($message, $messageConfiguration['data']); }