@@ -179,16 +179,11 @@ public function testShouldReceiveMessage()
179
179
$ this ->assertSame ('the body ' , $ message ->getBody ());
180
180
}
181
181
182
- public function testShouldReceiveMessageProtobufFormat ()
182
+ public function testShouldReceiveMessageUnSerialize ()
183
183
{
184
- $ body =
'[email protected] "[email protected] *&App\Tests\Entity\Entity497709 ' ;
185
- $ attributes = [
186
- 'ce-datacontenttype ' => 'application/protobuf ' ,
187
- ];
188
-
184
+ $ message = new GpsMessage ('the body ' );
189
185
$ nativeMessage = new Message ([
190
- 'data ' => $ body ,
191
- 'attributes ' => $ attributes ,
186
+ 'data ' => json_encode ($ message ),
192
187
], []);
193
188
194
189
$ subscription = $ this ->createSubscriptionMock ();
@@ -212,14 +207,64 @@ public function testShouldReceiveMessageProtobufFormat()
212
207
->expects ($ this ->once ())
213
208
->method ('getClient ' )
214
209
->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 ]);
215
260
216
261
$ consumer = new GpsConsumer ($ context , new GpsQueue ('queue-name ' ));
217
262
218
263
$ message = $ consumer ->receive (12345 );
219
264
220
265
$ 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 ());
223
268
}
224
269
225
270
/**
0 commit comments