File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
src/Symfony/Component/Notifier Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,17 @@ final class SmsMessage implements MessageInterface
23
23
private $ transport ;
24
24
private $ subject ;
25
25
private $ phone ;
26
+ private $ options ;
26
27
27
- public function __construct (string $ phone , string $ subject )
28
+ public function __construct (string $ phone , string $ subject, ? MessageOptionsInterface $ options = null )
28
29
{
29
30
if ('' === $ phone ) {
30
31
throw new InvalidArgumentException (sprintf ('"%s" needs a phone number, it cannot be empty. ' , static ::class));
31
32
}
32
33
33
34
$ this ->subject = $ subject ;
34
35
$ this ->phone = $ phone ;
36
+ $ this ->options = $ options ;
35
37
}
36
38
37
39
public static function fromNotification (Notification $ notification , SmsRecipientInterface $ recipient ): self
@@ -93,8 +95,18 @@ public function getTransport(): ?string
93
95
return $ this ->transport ;
94
96
}
95
97
98
+ /**
99
+ * @return $this
100
+ */
101
+ public function options (?MessageOptionsInterface $ options ): self
102
+ {
103
+ $ this ->options = $ options ;
104
+
105
+ return $ this ;
106
+ }
107
+
96
108
public function getOptions (): ?MessageOptionsInterface
97
109
{
98
- return null ;
110
+ return $ this -> options ;
99
111
}
100
112
}
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \Notifier \Tests \Message ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Notifier \Message \MessageOptionsInterface ;
15
16
use Symfony \Component \Notifier \Message \SmsMessage ;
16
17
17
18
/**
@@ -57,4 +58,27 @@ public function testEnsureNonEmptyPhoneOnSet()
57
58
58
59
$ message ->phone ('' );
59
60
}
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
+ }
60
84
}
You can’t perform that action at this time.
0 commit comments