File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
5
5
---
6
6
7
7
* Add PHPUnit constraints
8
+ * Add ` from ` property in ` SmsMessage `
8
9
9
10
6.1
10
11
---
Original file line number Diff line number Diff line change @@ -23,15 +23,17 @@ class SmsMessage implements MessageInterface
23
23
private ?string $ transport = null ;
24
24
private string $ subject ;
25
25
private string $ phone ;
26
+ private string $ from ;
26
27
27
- public function __construct (string $ phone , string $ subject )
28
+ public function __construct (string $ phone , string $ subject, string $ from = '' )
28
29
{
29
30
if ('' === $ phone ) {
30
31
throw new InvalidArgumentException (sprintf ('"%s" needs a phone number, it cannot be empty. ' , __CLASS__ ));
31
32
}
32
33
33
34
$ this ->subject = $ subject ;
34
35
$ this ->phone = $ phone ;
36
+ $ this ->from = $ from ;
35
37
}
36
38
37
39
public static function fromNotification (Notification $ notification , SmsRecipientInterface $ recipient ): self
@@ -93,6 +95,21 @@ public function getTransport(): ?string
93
95
return $ this ->transport ;
94
96
}
95
97
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
+
96
113
public function getOptions (): ?MessageOptionsInterface
97
114
{
98
115
return null ;
Original file line number Diff line number Diff line change @@ -25,6 +25,16 @@ public function testCanBeConstructed()
25
25
26
26
$ this ->assertSame ('subject ' , $ message ->getSubject ());
27
27
$ 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 ());
28
38
}
29
39
30
40
public function testEnsureNonEmptyPhoneOnConstruction ()
@@ -57,4 +67,15 @@ public function testEnsureNonEmptyPhoneOnSet()
57
67
58
68
$ message ->phone ('' );
59
69
}
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
+ }
60
81
}
You can’t perform that action at this time.
0 commit comments