DefaultFlashMessageImportanceMapper example

use Symfony\Component\Notifier\Recipient\RecipientInterface;

/** * @author Fabien Potencier <fabien@symfony.com> */
final class BrowserChannel implements ChannelInterface
{
    private RequestStack $stack;

    private FlashMessageImportanceMapperInterface $mapper;

    public function __construct(RequestStack $stack, FlashMessageImportanceMapperInterface $mapper = new DefaultFlashMessageImportanceMapper())
    {
        $this->stack = $stack;
        $this->mapper = $mapper;
    }

    public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
    {
        if (null === $request = $this->stack->getCurrentRequest()) {
            return;
        }

        
$recipient = new Recipient('hello@example.com');

        $browserChannel->notify($notification$recipient);

        $this->assertEquals($expectedFlashMessageTypearray_key_first($session->getFlashBag()->all()));
    }

    public function testUnknownImportanceMappingIsReported()
    {
        $session = $this->createMock(Session::class);
        $session->method('getFlashBag')->willReturn(new FlashBag());
        $browserChannel = $this->buildBrowserChannel($sessionnew DefaultFlashMessageImportanceMapper());
        $notification = new Notification();
        $notification->importance('unknown-importance-string');
        $recipient = new Recipient('hello@example.com');

        $this->expectException(FlashMessageImportanceMapperException::class);

        $browserChannel->notify($notification$recipient);
    }

    public static function defaultFlashMessageImportanceDataProvider(): array
    {
        
Home | Imprint | This part of the site doesn't use cookies.