File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed
Tests/Transport/Serialization Expand file tree Collapse file tree 2 files changed +74
-0
lines changed 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 <[email protected] >
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 \Messenger \Tests \Transport \Serialization ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Messenger \Envelope ;
16
+ use Symfony \Component \Messenger \Tests \Fixtures \DummyMessage ;
17
+ use Symfony \Component \Messenger \Transport \Serialization \PhpSerializer ;
18
+
19
+ class PhpSerializerTest extends TestCase
20
+ {
21
+ public function testEncodedIsDecodable ()
22
+ {
23
+ $ serializer = new PhpSerializer ();
24
+
25
+ $ envelope = new Envelope (new DummyMessage ('Hello ' ));
26
+
27
+ $ this ->assertEquals ($ envelope , $ serializer ->decode ($ serializer ->encode ($ envelope )));
28
+ }
29
+ }
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 <[email protected] >
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 \Messenger \Transport \Serialization ;
13
+
14
+ use Symfony \Component \Messenger \Envelope ;
15
+ use Symfony \Component \Messenger \Exception \InvalidArgumentException ;
16
+
17
+ /**
18
+ * @author Ruyan Weaver<[email protected] >
19
+ *
20
+ * @experimental in 4.2
21
+ */
22
+ class PhpSerializer implements SerializerInterface
23
+ {
24
+ /**
25
+ * {@inheritdoc}
26
+ */
27
+ public function decode (array $ encodedEnvelope ): Envelope
28
+ {
29
+ if (empty ($ encodedEnvelope ['body ' ])) {
30
+ throw new InvalidArgumentException ('Encoded envelope should have at least a "body". ' );
31
+ }
32
+
33
+ return unserialize ($ encodedEnvelope ['body ' ]);
34
+ }
35
+
36
+ /**
37
+ * {@inheritdoc}
38
+ */
39
+ public function encode (Envelope $ envelope ): array
40
+ {
41
+ return [
42
+ 'body ' => serialize ($ envelope ),
43
+ ];
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments