20
20
21
21
class PhpSerializerTest extends TestCase
22
22
{
23
- public function testEncodedIsDecodable ()
23
+ public function testEncodedIsDecodable (): void
24
24
{
25
25
$ serializer = new PhpSerializer ();
26
26
@@ -31,53 +31,53 @@ public function testEncodedIsDecodable()
31
31
$ this ->assertEquals ($ envelope , $ serializer ->decode ($ encoded ));
32
32
}
33
33
34
- public function testDecodingFailsWithMissingBodyKey ()
34
+ public function testDecodingFailsWithMissingBodyKey (): void
35
35
{
36
+ $ serializer = new PhpSerializer ();
37
+
36
38
$ this ->expectException (MessageDecodingFailedException::class);
37
39
$ this ->expectExceptionMessage ('Encoded envelope should have at least a "body", or maybe you should implement your own serializer ' );
38
40
39
- $ serializer = new PhpSerializer ();
40
-
41
41
$ serializer ->decode ([]);
42
42
}
43
43
44
- public function testDecodingFailsWithBadFormat ()
44
+ public function testDecodingFailsWithBadFormat (): void
45
45
{
46
+ $ serializer = new PhpSerializer ();
47
+
46
48
$ this ->expectException (MessageDecodingFailedException::class);
47
49
$ this ->expectExceptionMessageMatches ('/Could not decode/ ' );
48
50
49
- $ serializer = new PhpSerializer ();
50
-
51
51
$ serializer ->decode ([
52
52
'body ' => '{"message": "bar"} ' ,
53
53
]);
54
54
}
55
55
56
- public function testDecodingFailsWithBadBase64Body ()
56
+ public function testDecodingFailsWithBadBase64Body (): void
57
57
{
58
+ $ serializer = new PhpSerializer ();
59
+
58
60
$ this ->expectException (MessageDecodingFailedException::class);
59
61
$ this ->expectExceptionMessageMatches ('/Could not decode/ ' );
60
62
61
- $ serializer = new PhpSerializer ();
62
-
63
63
$ serializer ->decode ([
64
64
'body ' => 'x ' ,
65
65
]);
66
66
}
67
67
68
- public function testDecodingFailsWithBadClass ()
68
+ public function testDecodingFailsWithBadClass (): void
69
69
{
70
+ $ serializer = new PhpSerializer ();
71
+
70
72
$ this ->expectException (MessageDecodingFailedException::class);
71
73
$ this ->expectExceptionMessageMatches ('/class "ReceivedSt0mp" not found/ ' );
72
74
73
- $ serializer = new PhpSerializer ();
74
-
75
75
$ serializer ->decode ([
76
76
'body ' => 'O:13:"ReceivedSt0mp":0:{} ' ,
77
77
]);
78
78
}
79
79
80
- public function testEncodedSkipsNonEncodeableStamps ()
80
+ public function testEncodedSkipsNonEncodeableStamps (): void
81
81
{
82
82
$ serializer = new PhpSerializer ();
83
83
@@ -89,7 +89,7 @@ public function testEncodedSkipsNonEncodeableStamps()
89
89
$ this ->assertStringNotContainsString ('DummyPhpSerializerNonSendableStamp ' , $ encoded ['body ' ]);
90
90
}
91
91
92
- public function testNonUtf8IsBase64Encoded ()
92
+ public function testNonUtf8IsBase64Encoded (): void
93
93
{
94
94
$ serializer = new PhpSerializer ();
95
95
@@ -99,6 +99,19 @@ public function testNonUtf8IsBase64Encoded()
99
99
$ this ->assertTrue ((bool ) preg_match ('//u ' , $ encoded ['body ' ]), 'Encodes non-UTF8 payloads ' );
100
100
$ this ->assertEquals ($ envelope , $ serializer ->decode ($ encoded ));
101
101
}
102
+
103
+ public function testDecodingFailsForPropertyTypeMismatch (): void
104
+ {
105
+ $ serializer = new PhpSerializer ();
106
+ $ encodedEnvelope = $ serializer ->encode (new Envelope (new DummyMessage ('true ' )));
107
+ // Simulate a change of property type in the code base
108
+ $ encodedEnvelope ['body ' ] = str_replace ('s:4:\"true\" ' , 'b:1 ' , $ encodedEnvelope ['body ' ]);
109
+
110
+ $ this ->expectException (MessageDecodingFailedException::class);
111
+ $ this ->expectExceptionMessageMatches ('/Could not decode/ ' );
112
+
113
+ $ serializer ->decode ($ encodedEnvelope );
114
+ }
102
115
}
103
116
104
117
class DummyPhpSerializerNonSendableStamp implements NonSendableStampInterface
0 commit comments