Skip to content

Commit 946d018

Browse files
committed
[Notifier] Add from in SmsMessage and support it in bridge transports
1 parent 3ad5f94 commit 946d018

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add PHPUnit constraints
8+
* Add `from` property in `SmsMessage`
89

910
6.1
1011
---

Message/SmsMessage.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ class SmsMessage implements MessageInterface
2323
private ?string $transport = null;
2424
private string $subject;
2525
private string $phone;
26+
private string $from;
2627

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

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

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

98+
/**
99+
* @return $this
100+
*/
101+
public function from(string $from): static
102+
{
103+
$this->from = $from;
104+
105+
return $this;
106+
}
107+
108+
public function getFrom(): string
109+
{
110+
return $this->from;
111+
}
112+
96113
public function getOptions(): ?MessageOptionsInterface
97114
{
98115
return null;

Tests/Message/SmsMessageTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public function testCanBeConstructed()
2525

2626
$this->assertSame('subject', $message->getSubject());
2727
$this->assertSame('+3312345678', $message->getPhone());
28+
$this->assertSame('', $message->getFrom());
29+
}
30+
31+
public function testCanBeConstructedWithFrom()
32+
{
33+
$message = new SmsMessage('+3312345678', 'subject', 'foo');
34+
35+
$this->assertSame('subject', $message->getSubject());
36+
$this->assertSame('+3312345678', $message->getPhone());
37+
$this->assertSame('foo', $message->getFrom());
2838
}
2939

3040
public function testEnsureNonEmptyPhoneOnConstruction()
@@ -57,4 +67,15 @@ public function testEnsureNonEmptyPhoneOnSet()
5767

5868
$message->phone('');
5969
}
70+
71+
public function testSetFrom()
72+
{
73+
$message = new SmsMessage('+3312345678', 'subject');
74+
75+
$this->assertSame('', $message->getFrom());
76+
77+
$message->from('foo');
78+
79+
$this->assertSame('foo', $message->getFrom());
80+
}
6081
}

0 commit comments

Comments
 (0)