From 553fe978bc37497de7d191c0394e579172421812 Mon Sep 17 00:00:00 2001 From: Alex Rubia Date: Mon, 27 Dec 2021 15:22:23 +0100 Subject: [PATCH 1/3] Change Serialize method --- src/ExternalEvents.php | 4 ++-- tests/ExternalEventsTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ExternalEvents.php b/src/ExternalEvents.php index 34061dc..54aa948 100644 --- a/src/ExternalEvents.php +++ b/src/ExternalEvents.php @@ -27,7 +27,7 @@ public static function publish(Message $class): void ) ); $message = [ - 'data' => $class->serializeToString(), + 'data' => $class->serializeToJsonString(), ]; publish($routingKey, $message); @@ -40,7 +40,7 @@ public static function decode(string $expectedEvent, string $message): mixed { try { $event = new $expectedEvent(); - $event->mergeFromString($message); + $event->mergeFromJsonString($message); return $event; } catch (Exception) { diff --git a/tests/ExternalEventsTest.php b/tests/ExternalEventsTest.php index a1cbbc3..10aa36d 100644 --- a/tests/ExternalEventsTest.php +++ b/tests/ExternalEventsTest.php @@ -23,7 +23,7 @@ public function whenDecodeMessageItShouldReturnTheMessageObject(): void { $message = new FakeMessage(); $message->setContent(':content:'); - $codedMessage = $message->serializeToString(); + $codedMessage = $message->serializeToJsonString(); $decodedMessage = ExternalEvents::decode(FakeMessage::class, $codedMessage); self::assertSame(':content:', $decodedMessage->getContent()); @@ -89,6 +89,6 @@ public function handle(FakeMessage $message) $message = new FakeMessage(); $message->setContent(':content:'); - ExternalEvents::decorateListener($listener::class)(['data' => $message->serializeToString()]); + ExternalEvents::decorateListener($listener::class)(['data' => $message->serializeToJsonString()]); } } From 5f8c9f66b9d06999e18a79629b46f43d8a282f1e Mon Sep 17 00:00:00 2001 From: Alex Rubia Date: Tue, 28 Dec 2021 08:49:38 +0100 Subject: [PATCH 2/3] Fix assert test --- tests/ExternalEventsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ExternalEventsTest.php b/tests/ExternalEventsTest.php index 10aa36d..9abecc0 100644 --- a/tests/ExternalEventsTest.php +++ b/tests/ExternalEventsTest.php @@ -11,7 +11,7 @@ function publish($routingKey, $message) { assertSame('softonic.laravel_protobuf_events.fake_proto.fake_message', $routingKey); - assertSame(['data' => "\n :content:"], $message); + assertSame(['data' => '***"content":":content:"***'], $message); } class ExternalEventsTest extends TestCase From e03b5e31593da1c27099b99986b7c48bb2e7a0a4 Mon Sep 17 00:00:00 2001 From: Alex Rubia Date: Tue, 28 Dec 2021 08:53:30 +0100 Subject: [PATCH 3/3] Fix assert test --- tests/ExternalEventsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ExternalEventsTest.php b/tests/ExternalEventsTest.php index 9abecc0..a678073 100644 --- a/tests/ExternalEventsTest.php +++ b/tests/ExternalEventsTest.php @@ -11,7 +11,7 @@ function publish($routingKey, $message) { assertSame('softonic.laravel_protobuf_events.fake_proto.fake_message', $routingKey); - assertSame(['data' => '***"content":":content:"***'], $message); + assertSame(['data' => '{"content":":content:"}'], $message); } class ExternalEventsTest extends TestCase