Skip to content

Commit 56e5dde

Browse files
committed
Added ability to initialize sms options
1 parent 76f02fd commit 56e5dde

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ final class SmsMessage implements MessageInterface
2323
private $transport;
2424
private $subject;
2525
private $phone;
26+
private $options;
2627

27-
public function __construct(string $phone, string $subject)
28+
public function __construct(string $phone, string $subject, ?MessageOptionsInterface $options = null)
2829
{
2930
if ('' === $phone) {
3031
throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', static::class));
3132
}
3233

3334
$this->subject = $subject;
3435
$this->phone = $phone;
36+
$this->options = $options;
3537
}
3638

3739
public static function fromNotification(Notification $notification, SmsRecipientInterface $recipient): self
@@ -93,8 +95,18 @@ public function getTransport(): ?string
9395
return $this->transport;
9496
}
9597

98+
/**
99+
* @return $this
100+
*/
101+
public function options(?MessageOptionsInterface $options): self
102+
{
103+
$this->options = $options;
104+
105+
return $this;
106+
}
107+
96108
public function getOptions(): ?MessageOptionsInterface
97109
{
98-
return null;
110+
return $this->options;
99111
}
100112
}

src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Notifier\Tests\Message;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
1516
use Symfony\Component\Notifier\Message\SmsMessage;
1617

1718
/**
@@ -57,4 +58,27 @@ public function testEnsureNonEmptyPhoneOnSet()
5758

5859
$message->phone('');
5960
}
61+
62+
public function testSetOptions()
63+
{
64+
$options = new class implements MessageOptionsInterface {
65+
public function toArray(): array
66+
{
67+
return [];
68+
}
69+
70+
public function getRecipientId(): ?string
71+
{
72+
return 'id';
73+
}
74+
};
75+
76+
$message = new SmsMessage('+3715673920', 'subject', $options);
77+
78+
$this->assertInstanceOf(MessageOptionsInterface::class, $message->getOptions());
79+
80+
$message->options(null);
81+
82+
$this->assertNull($message->getOptions());
83+
}
6084
}

0 commit comments

Comments
 (0)