@@ -80,15 +80,18 @@ public function testUsesTheCustomFormatAndContext()
80
80
$ this ->assertSame ($ message , $ decoded ->getMessage ());
81
81
}
82
82
83
- public function testEncodedWithSerializationConfiguration ()
83
+ public function testEncodedWithSerializationConfigurationUsingPhpSerialize ()
84
84
{
85
85
$ serializer = new Serializer (
86
- new SerializerComponent \Serializer (array (new ObjectNormalizer ()), array ('json ' => new JsonEncoder ()))
86
+ new SerializerComponent \Serializer (array (new ObjectNormalizer ()), array ('json ' => new JsonEncoder ())),
87
+ 'json ' ,
88
+ array (),
89
+ true
87
90
);
88
91
89
92
$ envelope = Envelope::wrap (new DummyMessage ('Hello ' ))
90
- ->with (new SerializerConfiguration (array (ObjectNormalizer::GROUPS => array ('foo ' ))))
91
- ->with (new ValidationConfiguration (array ('foo ' , 'bar ' )))
93
+ ->with ($ serializerConfiguration = new SerializerConfiguration (array (ObjectNormalizer::GROUPS => array ('foo ' ))))
94
+ ->with ($ validationConfiguration = new ValidationConfiguration (array ('foo ' , 'bar ' )))
92
95
;
93
96
94
97
$ encoded = $ serializer ->encode ($ envelope );
@@ -99,5 +102,37 @@ public function testEncodedWithSerializationConfiguration()
99
102
$ this ->assertEquals (DummyMessage::class, $ encoded ['headers ' ]['type ' ]);
100
103
$ this ->assertArrayHasKey ('X-Message-Envelope-Items ' , $ encoded ['headers ' ]);
101
104
$ this ->assertSame ('a:2:{s:75:"Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration";C:75:"Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration":59:{a:1:{s:7:"context";a:1:{s:6:"groups";a:1:{i:0;s:3:"foo";}}}}s:76:"Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration";C:76:"Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration":82:{a:2:{s:6:"groups";a:2:{i:0;s:3:"foo";i:1;s:3:"bar";}s:17:"is_group_sequence";b:0;}}} ' , $ encoded ['headers ' ]['X-Message-Envelope-Items ' ]);
105
+
106
+ $ decoded = $ serializer ->decode ($ encoded );
107
+
108
+ $ this ->assertEquals ($ serializerConfiguration , $ decoded ->get (SerializerConfiguration::class));
109
+ $ this ->assertEquals ($ validationConfiguration , $ decoded ->get (ValidationConfiguration::class));
110
+ }
111
+
112
+ public function testEncodedWithSymfonySerializerForItems ()
113
+ {
114
+ $ serializer = new Serializer (
115
+ new SerializerComponent \Serializer (array (new ObjectNormalizer ()), array ('json ' => new JsonEncoder ())),
116
+ 'json ' ,
117
+ array ()
118
+ );
119
+
120
+ $ envelope = Envelope::wrap (new DummyMessage ('Hello ' ))
121
+ ->with ($ serializerConfiguration = new SerializerConfiguration (array (ObjectNormalizer::GROUPS => array ('foo ' ))))
122
+ ->with ($ validationConfiguration = new ValidationConfiguration (array ('foo ' , 'bar ' )))
123
+ ;
124
+
125
+ $ encoded = $ serializer ->encode ($ envelope );
126
+
127
+ $ this ->assertArrayHasKey ('body ' , $ encoded );
128
+ $ this ->assertArrayHasKey ('headers ' , $ encoded );
129
+ $ this ->assertArrayHasKey ('type ' , $ encoded ['headers ' ]);
130
+ $ this ->assertArrayHasKey ('X-Message-Envelope-Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration ' , $ encoded ['headers ' ]);
131
+ $ this ->assertArrayHasKey ('X-Message-Envelope-Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration ' , $ encoded ['headers ' ]);
132
+
133
+ $ decoded = $ serializer ->decode ($ encoded );
134
+
135
+ $ this ->assertEquals ($ serializerConfiguration , $ decoded ->get (SerializerConfiguration::class));
136
+ $ this ->assertEquals ($ validationConfiguration , $ decoded ->get (ValidationConfiguration::class));
102
137
}
103
138
}
0 commit comments