importance example


    public function testImportanceLevelIsReflectedInFlashMessageType(
        FlashMessageImportanceMapperInterface $mapper,
        string $importance,
        string $expectedFlashMessageType
    ) {
        $session = $this->createMock(Session::class);
        $session->method('getFlashBag')->willReturn(new FlashBag());
        $browserChannel = $this->buildBrowserChannel($session$mapper);
        $notification = new Notification();
        $notification->importance($importance);
        $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());
        


    /** * @return $this */
    public function exception(\Throwable|FlattenException $exception)static
    {
        $exceptionAsString = $this->getExceptionAsString($exception);

        $this->context['exception'] = true;
        $this->addPart(new DataPart($exceptionAsString, 'exception.txt', 'text/plain'));
        $this->importance(self::IMPORTANCE_URGENT);

        if (!$this->getSubject()) {
            $this->subject($exception->getMessage());
        }

        return $this;
    }

    /** * @return $this */
    
public function onMessageFailed(WorkerMessageFailedEvent $event)
    {
        if ($event->willRetry()) {
            return;
        }

        $throwable = $event->getThrowable();
        if ($throwable instanceof HandlerFailedException) {
            $throwable = $throwable->getNestedExceptions()[0];
        }
        $envelope = $event->getEnvelope();
        $notification = Notification::fromThrowable($throwable)->importance(Notification::IMPORTANCE_HIGH);
        $notification->subject(sprintf('A "%s" message has just failed: %s.', $envelope->getMessage()::class$notification->getSubject()));

        $this->notifier->send($notification, ...$this->notifier->getAdminRecipients());
    }

    public static function getSubscribedEvents(): array
    {
        return [
            WorkerMessageFailedEvent::class => 'onMessageFailed',
        ];
    }
}
if (!class_exists(NotificationEmail::class)) {
            $email = (new Email())
                ->to($recipient->getEmail())
                ->subject($notification->getSubject())
                ->text($notification->getContent() ?: $notification->getSubject())
            ;
        } else {
            $email = (new NotificationEmail())
                ->to($recipient->getEmail())
                ->subject($notification->getSubject())
                ->content($notification->getContent() ?: $notification->getSubject())
                ->importance($notification->getImportance())
            ;

            if ($exception = $notification->getException()) {
                $email->exception($exception);
            }
        }

        $message = new self($email);
        $message->notification = $notification;

        return $message;
    }
use Symfony\Component\Notifier\Bridge\Mobyt\MobytOptions;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Notification\Notification;

final class MobytOptionsTest extends TestCase
{
    /** * @dataProvider fromNotificationDataProvider */
    public function testFromNotification(string $importance, string $expectedMessageType)
    {
        $notification = (new Notification('Foo'))->importance($importance);

        $options = MobytOptions::fromNotification($notification)->toArray();

        $this->assertSame($expectedMessageType$options['message_type']);
    }

    /** * @return \Generator<array{0: string, 1: string}> */
    public static function fromNotificationDataProvider(): \Generator
    {
        
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Mime\NotificationEmail;

class NotificationEmailTest extends TestCase
{
    public function test()
    {
        $email = (new NotificationEmail())
            ->markdown('Foo')
            ->exception(new \Exception())
            ->importance(NotificationEmail::IMPORTANCE_HIGH)
            ->action('Bar', 'http://example.com/')
            ->context(['a' => 'b'])
        ;

        $this->assertEquals([
            'importance' => NotificationEmail::IMPORTANCE_HIGH,
            'content' => 'Foo',
            'exception' => true,
            'action_text' => 'Bar',
            'action_url' => 'http://example.com/',
            'markdown' => true,
            
final class NotificationController
{
    public function indexAction(NotifierInterface $notifier)
    {
        $firstNotification = new Notification('Hello World!', ['chat/slack']);
        $firstNotification->content('Symfony is awesome!');

        $notifier->send($firstNotification);

        $secondNotification = (new Notification('New urgent notification'))
            ->importance(Notification::IMPORTANCE_URGENT)
        ;
        $notifier->send($secondNotification);

        return new Response();
    }
}
Home | Imprint | This part of the site doesn't use cookies.