Skip to content

[Notifier] Transport possible to have null #51276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
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
{
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);

$thirdNotification = new Notification('Hello World!', ['sms']);
$thirdNotification->content('Symfony is awesome!');
$notifier->send($thirdNotification, new Recipient('', '112'));

return new Response();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ framework:
urgent: ['chat/mercure']
admin_recipients:
- { email: admin@example.com }
texter_transports:
smsbiuras: 'null://null'
profiler: ~

mercure:
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Message/NullMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function getOptions(): ?MessageOptionsInterface

public function getTransport(): ?string
{
return $this->decoratedMessage->getTransport() ?? 'null';
return $this->decoratedMessage->getTransport() ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down