File tree 4 files changed +44
-5
lines changed
src/Symfony/Component/Messenger
Tests/Transport/Serialization
4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ public function testEncodedIsDecodable()
28
28
$ this ->assertEquals ($ envelope , $ serializer ->decode ($ serializer ->encode ($ envelope )));
29
29
}
30
30
31
+ public function testDecodingFailsWithMissingBodyKey ()
32
+ {
33
+ $ this ->expectException (MessageDecodingFailedException::class);
34
+ $ this ->expectExceptionMessage ('Encoded envelope should have at least a "body". ' );
35
+
36
+ $ serializer = new PhpSerializer ();
37
+
38
+ $ serializer ->decode ([]);
39
+ }
40
+
31
41
public function testDecodingFailsWithBadFormat ()
32
42
{
33
43
$ this ->expectException (MessageDecodingFailedException::class);
Original file line number Diff line number Diff line change @@ -108,6 +108,37 @@ public function testDecodingFailsWithBadFormat()
108
108
]);
109
109
}
110
110
111
+ /**
112
+ * @dataProvider getMissingKeyTests
113
+ */
114
+ public function testDecodingFailsWithMissingKeys (array $ data , string $ expectedMessage )
115
+ {
116
+ $ this ->expectException (MessageDecodingFailedException::class);
117
+ $ this ->expectExceptionMessage ($ expectedMessage );
118
+
119
+ $ serializer = new Serializer ();
120
+
121
+ $ serializer ->decode ($ data );
122
+ }
123
+
124
+ public function getMissingKeyTests ()
125
+ {
126
+ yield 'no_body ' => [
127
+ ['headers ' => ['type ' => 'bar ' ]],
128
+ 'Encoded envelope should have at least a "body" and some "headers". ' ,
129
+ ];
130
+
131
+ yield 'no_headers ' => [
132
+ ['body ' => '{} ' ],
133
+ 'Encoded envelope should have at least a "body" and some "headers". ' ,
134
+ ];
135
+
136
+ yield 'no_headers_type ' => [
137
+ ['body ' => '{} ' , 'headers ' => ['foo ' => 'bar ' ]],
138
+ 'Encoded envelope does not have a "type" header. ' ,
139
+ ];
140
+ }
141
+
111
142
public function testDecodingFailsWithBadClass ()
112
143
{
113
144
$ this ->expectException (MessageDecodingFailedException::class);
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \Messenger \Transport \Serialization ;
13
13
14
14
use Symfony \Component \Messenger \Envelope ;
15
- use Symfony \Component \Messenger \Exception \InvalidArgumentException ;
16
15
use Symfony \Component \Messenger \Exception \MessageDecodingFailedException ;
17
16
18
17
/**
@@ -28,7 +27,7 @@ class PhpSerializer implements SerializerInterface
28
27
public function decode (array $ encodedEnvelope ): Envelope
29
28
{
30
29
if (empty ($ encodedEnvelope ['body ' ])) {
31
- throw new InvalidArgumentException ('Encoded envelope should have at least a "body". ' );
30
+ throw new MessageDecodingFailedException ('Encoded envelope should have at least a "body". ' );
32
31
}
33
32
34
33
return $ this ->safelyUnserialize ($ encodedEnvelope ['body ' ]);
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \Messenger \Transport \Serialization ;
13
13
14
14
use Symfony \Component \Messenger \Envelope ;
15
- use Symfony \Component \Messenger \Exception \InvalidArgumentException ;
16
15
use Symfony \Component \Messenger \Exception \LogicException ;
17
16
use Symfony \Component \Messenger \Exception \MessageDecodingFailedException ;
18
17
use Symfony \Component \Messenger \Stamp \SerializerStamp ;
@@ -63,11 +62,11 @@ public static function create(): self
63
62
public function decode (array $ encodedEnvelope ): Envelope
64
63
{
65
64
if (empty ($ encodedEnvelope ['body ' ]) || empty ($ encodedEnvelope ['headers ' ])) {
66
- throw new InvalidArgumentException ('Encoded envelope should have at least a "body" and some "headers". ' );
65
+ throw new MessageDecodingFailedException ('Encoded envelope should have at least a "body" and some "headers". ' );
67
66
}
68
67
69
68
if (empty ($ encodedEnvelope ['headers ' ]['type ' ])) {
70
- throw new InvalidArgumentException ('Encoded envelope does not have a "type" header. ' );
69
+ throw new MessageDecodingFailedException ('Encoded envelope does not have a "type" header. ' );
71
70
}
72
71
73
72
$ stamps = $ this ->decodeStamps ($ encodedEnvelope );
You can’t perform that action at this time.
0 commit comments