Skip to content

Commit 9dd7770

Browse files
committed
Supporting protobuf message support
1 parent bb6e759 commit 9dd7770

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

pkg/gps/GpsConsumer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function getSubscription(): Subscription
110110

111111
private function convertMessage(GoogleMessage $message): GpsMessage
112112
{
113-
$gpsMessage = GpsMessage::jsonUnserialize($message->data());
113+
$gpsMessage = new GpsMessage($message->data(), $message->attributes(),[]);
114114
$gpsMessage->setNativeMessage($message);
115115

116116
return $gpsMessage;

pkg/gps/Tests/GpsConsumerTest.php

+43
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,49 @@ public function testShouldReceiveMessage()
179179
$this->assertSame('the body', $message->getBody());
180180
}
181181

182+
public function testShouldReceiveMessageProtobufFormat()
183+
{
184+
$body = '[email protected]"[email protected]*&App\Tests\Entity\Entity497709';
185+
$attributes = [
186+
'ce-datacontenttype' => 'application/protobuf',
187+
];
188+
189+
$nativeMessage = new Message([
190+
'data' => $body,
191+
'attributes' => $attributes,
192+
], []);
193+
194+
$subscription = $this->createSubscriptionMock();
195+
$subscription
196+
->expects($this->once())
197+
->method('pull')
198+
->with($this->identicalTo([
199+
'maxMessages' => 1,
200+
'requestTimeout' => 12.345,
201+
]))
202+
->willReturn([$nativeMessage]);
203+
204+
$client = $this->createPubSubClientMock();
205+
$client
206+
->expects($this->once())
207+
->method('subscription')
208+
->willReturn($subscription);
209+
210+
$context = $this->createContextMock();
211+
$context
212+
->expects($this->once())
213+
->method('getClient')
214+
->willReturn($client);
215+
216+
$consumer = new GpsConsumer($context, new GpsQueue('queue-name'));
217+
218+
$message = $consumer->receive(12345);
219+
220+
$this->assertInstanceOf(GpsMessage::class, $message);
221+
$this->assertSame($body, $message->getBody());
222+
$this->assertSame($attributes, $message->getProperties());
223+
}
224+
182225
/**
183226
* @return \PHPUnit\Framework\MockObject\MockObject|GpsContext
184227
*/

0 commit comments

Comments
 (0)