Skip to content

Commit 7a03033

Browse files
committed
feature #51276 [Notifier] Transport possible to have null (StaffNowa)
This PR was merged into the 6.4 branch. Discussion ---------- [Notifier] Transport possible to have null | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #51236 | License | MIT My test example of why I need to have properly transport null ```php public function testSmsSending(): void { $date = (new \DateTimeImmutable())->format('Y-m-d'); $stateta = new Stateta(); $stateta->setDate(new \DateTimeImmutable($date)); $stateta->setA95(0); $stateta->setDk(0); $this->entityManager->persist($stateta); $this->entityManager->flush(); $this->commandTester->execute([], [ 'verbosity' => OutputInterface::VERBOSITY_DEBUG ]); $this->commandTester->assertCommandIsSuccessful(); $notifierEvent = $this->getNotifierEvent(); self::assertEquals(null, $notifierEvent->getMessage()->getTransport()); self::assertEquals("+37061234567", $notifierEvent->getMessage()->getRecipientId()); self::assertNotificationIsQueued($notifierEvent); self::assertNotificationSubjectContains($notifierEvent->getMessage(), 'Company name'); self::assertNotificationTransportIsEqual($notifierEvent->getMessage(), null); } ``` Commits ------- 6120c4bd88 [Notifier] Transport possible to have null
2 parents b90a082 + a6752c9 commit 7a03033

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

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
}

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
}

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
}

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:

0 commit comments

Comments
 (0)