public function testTemplateArgumentReplacesTemplateMapConfiguration() { $channel = $this->getMock(NotificationChannelInterface::class); $channel->expects(self::once())->method('publish'); $user = User::create('Ma27', '123456', '*****@*****.**', new PhpPasswordHasher()); $class = 'AppBundle\\Model\\Core\\Handler\\SecretHandler'; $event = new NotificationInput(); $event->setLanguage('en')->addParameter('foo', 'bar')->addUser($user); $notificator = new ChannelDelegatingNotificator([], ['mail' => $channel]); $notificator->publishNotification($class, $event, ['mail'], 'AppBundle:Email/Secret:data'); self::assertSame('AppBundle:Email/Secret:data', $event->getTemplateSource()); }
/** * Creates the event and runs the notificator. * * @param mixed[] $parameters * @param \AppBundle\Model\User\User[] $users * @param string[] $channels * @param string $language * @param string|null $template * * @throws \LogicException If the dispatcher is not set. */ public function notify(array $parameters, array $users, array $channels = [], string $language = null, string $template = null) { if (!$this->notificator) { throw new \LogicException('Notification service must be set before running `NotificatableTrait::notify`!'); } $event = new NotificationInput(); if (null !== $language) { $event->setLanguage($language); } array_walk($users, [$event, 'addUser']); // can't flip and walk here since parameter values might be objects // and those must not be flipped. foreach ($parameters as $name => $value) { $event->addParameter($name, $value); } $this->notificator->publishNotification(get_class($this), $event, $channels, $template); }
public function setLocale() { $event = new NotificationInput(); $event->setLanguage('de'); $this->assertSame('de', $event->getLanguage()); }