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..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' => "\n :content:"], $message); + assertSame(['data' => '{"content":":content:"}'], $message); } class ExternalEventsTest extends TestCase @@ -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()]); } }