diff --git a/src/Symfony/Component/Notifier/Message/SmsMessage.php b/src/Symfony/Component/Notifier/Message/SmsMessage.php index f773512a8933b..729747ed5ee69 100644 --- a/src/Symfony/Component/Notifier/Message/SmsMessage.php +++ b/src/Symfony/Component/Notifier/Message/SmsMessage.php @@ -23,8 +23,9 @@ final class SmsMessage implements MessageInterface private $transport; private $subject; private $phone; + private $options; - public function __construct(string $phone, string $subject) + public function __construct(string $phone, string $subject, MessageOptionsInterface $options = null) { if ('' === $phone) { throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', static::class)); @@ -32,6 +33,7 @@ public function __construct(string $phone, string $subject) $this->subject = $subject; $this->phone = $phone; + $this->options = $options; } public static function fromNotification(Notification $notification, SmsRecipientInterface $recipient): self @@ -93,8 +95,18 @@ public function getTransport(): ?string return $this->transport; } + /** + * @return $this + */ + public function options(MessageOptionsInterface $options): self + { + $this->options = $options; + + return $this; + } + public function getOptions(): ?MessageOptionsInterface { - return null; + return $this->options; } } diff --git a/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php b/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php index 5dd0875a6f86f..5b73d02fff246 100644 --- a/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php +++ b/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Notifier\Tests\Message; use PHPUnit\Framework\TestCase; +use Symfony\Component\Notifier\Message\MessageOptionsInterface; use Symfony\Component\Notifier\Message\SmsMessage; /** @@ -57,4 +58,30 @@ public function testEnsureNonEmptyPhoneOnSet() $message->phone(''); } + + public function testOptionsDefaultsToNull() + { + $message = new SmsMessage('+3715673920', 'subject'); + + $this->assertNull($message->getOptions()); + } + + public function testSetOptions() + { + $options = new class() implements MessageOptionsInterface { + public function toArray(): array + { + return []; + } + + public function getRecipientId(): ?string + { + return 'id'; + } + }; + + $message = new SmsMessage('+3715673920', 'subject', $options); + + $this->assertInstanceOf(MessageOptionsInterface::class, $message->getOptions()); + } }