From f013832df3793627b300d63750f219f822f72970 Mon Sep 17 00:00:00 2001 From: Xavi Aparicio Date: Thu, 10 Mar 2022 18:43:05 +0100 Subject: [PATCH] Pass headers to protobuf --- src/ExternalEvents.php | 7 ++----- tests/ExternalEventsTest.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ExternalEvents.php b/src/ExternalEvents.php index bf86d68..3aa305f 100644 --- a/src/ExternalEvents.php +++ b/src/ExternalEvents.php @@ -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); } diff --git a/tests/ExternalEventsTest.php b/tests/ExternalEventsTest.php index 084b27b..ba00132 100644 --- a/tests/ExternalEventsTest.php +++ b/tests/ExternalEventsTest.php @@ -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); } @@ -55,7 +58,7 @@ public function whenDecodeAnInvalidMessageItShouldThrowAnException(): void /** * @test */ - public function whenPublishMessageItShouldPublishIt(): void + public function whenPublishMessageWithoutHeadersItShouldPublishIt(): void { $message = new FakeMessage(); $message->setContent(':content:'); @@ -99,7 +102,7 @@ public function process() /** * @test */ - public function whenDecoratingAListenerItShouldExecuteIt(): void + public function whenDecoratingAListenerWithoutHeadersItShouldExecuteIt(): void { $listener = new class() { public function handle(FakeMessage $message)