@@ -179,16 +179,11 @@ public function testShouldReceiveMessage()
179179 $ this ->assertSame ('the body ' , $ message ->getBody ());
180180 }
181181
182- public function testShouldReceiveMessageProtobufFormat ()
182+ public function testShouldReceiveMessageUnSerialize ()
183183 {
184- $ body = '2test+customer_6115118118117248@example.com"4test+customer_611511118118117248@example.com*&App\Tests\Entity\Entity497709 ' ;
185- $ attributes = [
186- 'ce-datacontenttype ' => 'application/protobuf ' ,
187- ];
188-
184+ $ message = new GpsMessage ('the body ' );
189185 $ nativeMessage = new Message ([
190- 'data ' => $ body ,
191- 'attributes ' => $ attributes ,
186+ 'data ' => json_encode ($ message ),
192187 ], []);
193188
194189 $ subscription = $ this ->createSubscriptionMock ();
@@ -212,14 +207,64 @@ public function testShouldReceiveMessageProtobufFormat()
212207 ->expects ($ this ->once ())
213208 ->method ('getClient ' )
214209 ->willReturn ($ client );
210+ $ context
211+ ->expects ($ this ->once ())
212+ ->method ('getOptions ' )
213+ ->willReturn (['serilalizeToJson ' => false ]);
214+
215+ $ consumer = new GpsConsumer ($ context , new GpsQueue ('queue-name ' ));
216+
217+ $ message = $ consumer ->receive (12345 );
218+
219+ $ this ->assertInstanceOf (GpsMessage::class, $ message );
220+ $ this ->assertSame ($ nativeMessage ->data (), $ message ->getBody ());
221+ $ this ->assertSame ($ nativeMessage ->attributes (), $ message ->getProperties ());
222+ }
223+
224+ public function testShouldReceiveMessageUnSerializeWithAttributes ()
225+ {
226+ $ message = new GpsMessage ('the body ' );
227+ $ nativeMessage = new Message ([
228+ 'data ' => json_encode ($ message ),
229+ 'attributes ' => [
230+ 'foo ' => 'fooVal ' ,
231+ 'bar ' => 'barVal ' ,
232+ ],
233+ ], []);
234+
235+ $ subscription = $ this ->createSubscriptionMock ();
236+ $ subscription
237+ ->expects ($ this ->once ())
238+ ->method ('pull ' )
239+ ->with ($ this ->identicalTo ([
240+ 'maxMessages ' => 1 ,
241+ 'requestTimeout ' => 12.345 ,
242+ ]))
243+ ->willReturn ([$ nativeMessage ]);
244+
245+ $ client = $ this ->createPubSubClientMock ();
246+ $ client
247+ ->expects ($ this ->once ())
248+ ->method ('subscription ' )
249+ ->willReturn ($ subscription );
250+
251+ $ context = $ this ->createContextMock ();
252+ $ context
253+ ->expects ($ this ->once ())
254+ ->method ('getClient ' )
255+ ->willReturn ($ client );
256+ $ context
257+ ->expects ($ this ->once ())
258+ ->method ('getOptions ' )
259+ ->willReturn (['serilalizeToJson ' => false ]);
215260
216261 $ consumer = new GpsConsumer ($ context , new GpsQueue ('queue-name ' ));
217262
218263 $ message = $ consumer ->receive (12345 );
219264
220265 $ this ->assertInstanceOf (GpsMessage::class, $ message );
221- $ this ->assertSame ($ body , $ message ->getBody ());
222- $ this ->assertSame ($ attributes , $ message ->getProperties ());
266+ $ this ->assertSame ($ nativeMessage -> data () , $ message ->getBody ());
267+ $ this ->assertSame ($ nativeMessage -> attributes () , $ message ->getProperties ());
223268 }
224269
225270 /**
0 commit comments