File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
55---
66
77 * Add ` Dsn::getBooleanOption() `
8+ * Add ` info ` property in ` SentMessage `
89
9107.2
1011---
Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ class SentMessage
1818{
1919 private ?string $ messageId = null ;
2020
21+ /**
22+ * @param array $info attaches any Transport-related information to the sent message
23+ */
2124 public function __construct (
2225 private MessageInterface $ original ,
2326 private string $ transport ,
27+ private array $ info = [],
2428 ) {
2529 }
2630
@@ -43,4 +47,18 @@ public function getMessageId(): ?string
4347 {
4448 return $ this ->messageId ;
4549 }
50+
51+ /**
52+ * Returns extra info attached to the message.
53+ *
54+ * @param string|null $key if null, the whole info array will be returned, else returns the info value or null
55+ */
56+ public function getInfo (?string $ key = null ): mixed
57+ {
58+ if (null !== $ key ) {
59+ return $ this ->info [$ key ] ?? null ;
60+ }
61+
62+ return $ this ->info ;
63+ }
4664}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <fabien@symfony.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Component \Notifier \Tests \Message ;
13+
14+ use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \Notifier \Message \SentMessage ;
16+ use Symfony \Component \Notifier \Tests \Transport \DummyMessage ;
17+
18+ class SentMessageTest extends TestCase
19+ {
20+ public function test ()
21+ {
22+ $ originalMessage = new DummyMessage ();
23+
24+ $ sentMessage = new SentMessage ($ originalMessage , 'any ' , ['foo ' => 'bar ' ]);
25+ $ sentMessage ->setMessageId ('the_id ' );
26+
27+ $ this ->assertSame ($ originalMessage , $ sentMessage ->getOriginalMessage ());
28+ $ this ->assertSame ('any ' , $ sentMessage ->getTransport ());
29+ $ this ->assertSame ('the_id ' , $ sentMessage ->getMessageId ());
30+ $ this ->assertSame (['foo ' => 'bar ' ], $ sentMessage ->getInfo ());
31+ $ this ->assertSame ('bar ' , $ sentMessage ->getInfo ('foo ' ));
32+ $ this ->assertNull ($ sentMessage ->getInfo ('not_existing ' ));
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments