Skip to content

Commit

Permalink
Merge pull request #2 from softonic/hotfix/Fix-Malformed-UTF-8-charac…
Browse files Browse the repository at this point in the history
…ters

Change Serialize method
  • Loading branch information
alexander-rubia authored Jan 11, 2022
2 parents 0c79795 + e03b5e3 commit 684fba1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ExternalEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function publish(Message $class): void
)
);
$message = [
'data' => $class->serializeToString(),
'data' => $class->serializeToJsonString(),
];

publish($routingKey, $message);
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ExternalEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down Expand Up @@ -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()]);
}
}

0 comments on commit 684fba1

Please sign in to comment.