Skip to content

Commit 6120c4b

Browse files
committed
[Notifier] Transport possible to have null
1 parent bb7a7dd commit 6120c4b

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/NotificationAssertionsTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public static function assertNotificationSubjectNotContains(MessageInterface $no
5252
self::assertThat($notification, new LogicalNot(new NotifierConstraint\NotificationSubjectContains($text)), $message);
5353
}
5454

55-
public static function assertNotificationTransportIsEqual(MessageInterface $notification, string $transportName, string $message = ''): void
55+
public static function assertNotificationTransportIsEqual(MessageInterface $notification, string $transportName = null, string $message = ''): void
5656
{
5757
self::assertThat($notification, new NotifierConstraint\NotificationTransportIsEqual($transportName), $message);
5858
}
5959

60-
public static function assertNotificationTransportIsNotEqual(MessageInterface $notification, string $transportName, string $message = ''): void
60+
public static function assertNotificationTransportIsNotEqual(MessageInterface $notification, string $transportName = null, string $message = ''): void
6161
{
6262
self::assertThat($notification, new LogicalNot(new NotifierConstraint\NotificationTransportIsEqual($transportName)), $message);
6363
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/NotificationController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@
1414
use Symfony\Component\HttpFoundation\Response;
1515
use Symfony\Component\Notifier\Notification\Notification;
1616
use Symfony\Component\Notifier\NotifierInterface;
17+
use Symfony\Component\Notifier\Recipient\Recipient;
1718

1819
final class NotificationController
1920
{
2021
public function indexAction(NotifierInterface $notifier)
2122
{
2223
$firstNotification = new Notification('Hello World!', ['chat/slack']);
2324
$firstNotification->content('Symfony is awesome!');
24-
2525
$notifier->send($firstNotification);
2626

2727
$secondNotification = (new Notification('New urgent notification'))
2828
->importance(Notification::IMPORTANCE_URGENT)
2929
;
3030
$notifier->send($secondNotification);
3131

32+
$thirdNotification = new Notification('Hello World!', ['sms']);
33+
$thirdNotification->content('Symfony is awesome!');
34+
$notifier->send($thirdNotification, new Recipient('', '112'));
35+
3236
return new Response();
3337
}
3438
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/NotificationTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public function testNotifierAssertion()
2121
$client = $this->createClient(['test_case' => 'Notifier', 'root_config' => 'config.yml', 'debug' => true]);
2222
$client->request('GET', '/send_notification');
2323

24-
$this->assertNotificationCount(2);
24+
$this->assertNotificationCount(3);
2525
$first = 0;
2626
$second = 1;
27+
$third = 2;
2728
$this->assertNotificationIsNotQueued($this->getNotifierEvent($first));
2829
$this->assertNotificationIsNotQueued($this->getNotifierEvent($second));
2930

@@ -38,5 +39,9 @@ public function testNotifierAssertion()
3839
$this->assertNotificationSubjectNotContains($notification, 'Hello World!');
3940
$this->assertNotificationTransportIsEqual($notification, 'mercure');
4041
$this->assertNotificationTransportIsNotEqual($notification, 'slack');
42+
43+
$notification = $this->getNotifierMessage($third);
44+
$this->assertNotificationSubjectContains($notification, 'Hello World!');
45+
$this->assertNotificationTransportIsEqual($notification, null);
4146
}
4247
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Notifier/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ framework:
1313
urgent: ['chat/mercure']
1414
admin_recipients:
1515
- { email: [email protected] }
16+
texter_transports:
17+
smsbiuras: 'null://null'
1618
profiler: ~
1719

1820
mercure:

src/Symfony/Component/Notifier/Message/NullMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public function getOptions(): ?MessageOptionsInterface
4040

4141
public function getTransport(): ?string
4242
{
43-
return $this->decoratedMessage->getTransport() ?? 'null';
43+
return $this->decoratedMessage->getTransport() ?? null;
4444
}
4545
}

src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
final class NotificationTransportIsEqual extends Constraint
2121
{
22-
private string $expectedText;
22+
private ?string $expectedText;
2323

24-
public function __construct(string $expectedText)
24+
public function __construct(?string $expectedText)
2525
{
2626
$this->expectedText = $expectedText;
2727
}

0 commit comments

Comments
 (0)