From 6120c4bd88c2469ef1b77dccb7de25d713d4d2f4 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Thu, 3 Aug 2023 18:51:26 +0300 Subject: [PATCH] [Notifier] Transport possible to have null --- .../FrameworkBundle/Test/NotificationAssertionsTrait.php | 4 ++-- .../TestBundle/Controller/NotificationController.php | 6 +++++- .../FrameworkBundle/Tests/Functional/NotificationTest.php | 7 ++++++- .../Tests/Functional/app/Notifier/config.yml | 2 ++ src/Symfony/Component/Notifier/Message/NullMessage.php | 2 +- .../Test/Constraint/NotificationTransportIsEqual.php | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php index 30298ef04c54f..f99836c89065f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php @@ -52,12 +52,12 @@ public static function assertNotificationSubjectNotContains(MessageInterface $no self::assertThat($notification, new LogicalNot(new NotifierConstraint\NotificationSubjectContains($text)), $message); } - public static function assertNotificationTransportIsEqual(MessageInterface $notification, string $transportName, string $message = ''): void + public static function assertNotificationTransportIsEqual(MessageInterface $notification, string $transportName = null, string $message = ''): void { self::assertThat($notification, new NotifierConstraint\NotificationTransportIsEqual($transportName), $message); } - public static function assertNotificationTransportIsNotEqual(MessageInterface $notification, string $transportName, string $message = ''): void + public static function assertNotificationTransportIsNotEqual(MessageInterface $notification, string $transportName = null, string $message = ''): void { self::assertThat($notification, new LogicalNot(new NotifierConstraint\NotificationTransportIsEqual($transportName)), $message); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/NotificationController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/NotificationController.php index 0cdb47c20f40a..ca86d8e9d185b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/NotificationController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/NotificationController.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Notifier\Notification\Notification; use Symfony\Component\Notifier\NotifierInterface; +use Symfony\Component\Notifier\Recipient\Recipient; final class NotificationController { @@ -21,7 +22,6 @@ 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')) @@ -29,6 +29,10 @@ public function indexAction(NotifierInterface $notifier) ; $notifier->send($secondNotification); + $thirdNotification = new Notification('Hello World!', ['sms']); + $thirdNotification->content('Symfony is awesome!'); + $notifier->send($thirdNotification, new Recipient('', '112')); + return new Response(); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/NotificationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/NotificationTest.php index c11211b02b675..03b947a0fb909 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/NotificationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/NotificationTest.php @@ -21,9 +21,10 @@ public function testNotifierAssertion() $client = $this->createClient(['test_case' => 'Notifier', 'root_config' => 'config.yml', 'debug' => true]); $client->request('GET', '/send_notification'); - $this->assertNotificationCount(2); + $this->assertNotificationCount(3); $first = 0; $second = 1; + $third = 2; $this->assertNotificationIsNotQueued($this->getNotifierEvent($first)); $this->assertNotificationIsNotQueued($this->getNotifierEvent($second)); @@ -38,5 +39,9 @@ public function testNotifierAssertion() $this->assertNotificationSubjectNotContains($notification, 'Hello World!'); $this->assertNotificationTransportIsEqual($notification, 'mercure'); $this->assertNotificationTransportIsNotEqual($notification, 'slack'); + + $notification = $this->getNotifierMessage($third); + $this->assertNotificationSubjectContains($notification, 'Hello World!'); + $this->assertNotificationTransportIsEqual($notification, null); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Notifier/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Notifier/config.yml index b8f28199a1fb4..8599ad1a1f520 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Notifier/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Notifier/config.yml @@ -13,6 +13,8 @@ framework: urgent: ['chat/mercure'] admin_recipients: - { email: admin@example.com } + texter_transports: + smsbiuras: 'null://null' profiler: ~ mercure: diff --git a/src/Symfony/Component/Notifier/Message/NullMessage.php b/src/Symfony/Component/Notifier/Message/NullMessage.php index 38a8c6b2af36d..7f6699e301493 100644 --- a/src/Symfony/Component/Notifier/Message/NullMessage.php +++ b/src/Symfony/Component/Notifier/Message/NullMessage.php @@ -40,6 +40,6 @@ public function getOptions(): ?MessageOptionsInterface public function getTransport(): ?string { - return $this->decoratedMessage->getTransport() ?? 'null'; + return $this->decoratedMessage->getTransport() ?? null; } } diff --git a/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php b/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php index cefa0cdc35dac..990e31daccdf2 100644 --- a/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php +++ b/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php @@ -19,9 +19,9 @@ */ final class NotificationTransportIsEqual extends Constraint { - private string $expectedText; + private ?string $expectedText; - public function __construct(string $expectedText) + public function __construct(?string $expectedText) { $this->expectedText = $expectedText; }