Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting protobuf message support #1329

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/gps/GpsConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function getSubscription(): Subscription

private function convertMessage(GoogleMessage $message): GpsMessage
{
$gpsMessage = GpsMessage::jsonUnserialize($message->data());
makasim marked this conversation as resolved.
Show resolved Hide resolved
$gpsMessage = new GpsMessage($message->data(), $message->attributes(),[]);
$gpsMessage->setNativeMessage($message);

return $gpsMessage;
Expand Down
43 changes: 43 additions & 0 deletions pkg/gps/Tests/GpsConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,49 @@ public function testShouldReceiveMessage()
$this->assertSame('the body', $message->getBody());
}

public function testShouldReceiveMessageProtobufFormat()
{
$body = '[email protected]"[email protected]*&App\Tests\Entity\Entity497709';
$attributes = [
'ce-datacontenttype' => 'application/protobuf',
];

$nativeMessage = new Message([
'data' => $body,
'attributes' => $attributes,
], []);

$subscription = $this->createSubscriptionMock();
$subscription
->expects($this->once())
->method('pull')
->with($this->identicalTo([
'maxMessages' => 1,
'requestTimeout' => 12.345,
]))
->willReturn([$nativeMessage]);

$client = $this->createPubSubClientMock();
$client
->expects($this->once())
->method('subscription')
->willReturn($subscription);

$context = $this->createContextMock();
$context
->expects($this->once())
->method('getClient')
->willReturn($client);

$consumer = new GpsConsumer($context, new GpsQueue('queue-name'));

$message = $consumer->receive(12345);

$this->assertInstanceOf(GpsMessage::class, $message);
$this->assertSame($body, $message->getBody());
$this->assertSame($attributes, $message->getProperties());
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|GpsContext
*/
Expand Down