Skip to content

Commit

Permalink
Pass headers to protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviapa committed Mar 10, 2022
1 parent bd2992c commit f013832
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/ExternalEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ public static function publish(Message $class, array $headers = []): void
);

$message = [
'data' => $class->serializeToJsonString(),
'data' => $class->serializeToJsonString(),
'headers' => $headers,
];

if ($headers) {
$message['headers'] = $headers;
}

publish($routingKey, $message);
}

Expand Down
13 changes: 8 additions & 5 deletions tests/ExternalEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ function publish($routingKey, $message)
{
assertSame('softonic.laravel_protobuf_events.fake_proto.fake_message', $routingKey);

if (array_key_exists('headers', $message)) {
if (empty($message['headers'])) {
$expectedMessage = [
'data' => '{"content":":content:"}',
'headers' => ['xRequestId' => '7b15d663-8d55-4e2f-82cc-4473576a4a17'],
'headers' => [],
];
} else {
$expectedMessage = ['data' => '{"content":":content:"}'];
$expectedMessage = [
'data' => '{"content":":content:"}',
'headers' => ['xRequestId' => '7b15d663-8d55-4e2f-82cc-4473576a4a17'],
];
}
assertSame($expectedMessage, $message);
}
Expand Down Expand Up @@ -55,7 +58,7 @@ public function whenDecodeAnInvalidMessageItShouldThrowAnException(): void
/**
* @test
*/
public function whenPublishMessageItShouldPublishIt(): void
public function whenPublishMessageWithoutHeadersItShouldPublishIt(): void
{
$message = new FakeMessage();
$message->setContent(':content:');
Expand Down Expand Up @@ -99,7 +102,7 @@ public function process()
/**
* @test
*/
public function whenDecoratingAListenerItShouldExecuteIt(): void
public function whenDecoratingAListenerWithoutHeadersItShouldExecuteIt(): void
{
$listener = new class() {
public function handle(FakeMessage $message)
Expand Down

0 comments on commit f013832

Please sign in to comment.