Skip to content

Commit

Permalink
Merge pull request #468: add ProtoBinary decoder in default set
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 2, 2024
2 parents b290246 + ebb28cc commit 6f70059
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/DataConverter/DataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static function createDefault(): DataConverterInterface
new NullConverter(),
new BinaryConverter(),
new ProtoJsonConverter(),
new ProtoConverter(),
new JsonConverter()
);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/DataConverter/DataConverterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
use PHPUnit\Framework\Attributes\DataProvider;
use Temporal\DataConverter\DataConverter;
use Temporal\DataConverter\DataConverterInterface;
use Temporal\DataConverter\EncodingKeys;
use Temporal\DataConverter\ProtoConverter;
use Temporal\DataConverter\ProtoJsonConverter;
use Temporal\DataConverter\Type;
use Temporal\Exception\DataConverterException;
use Temporal\Tests\Proto\Test;
use Temporal\Tests\Unit\AbstractUnit;

/**
Expand Down Expand Up @@ -177,4 +181,28 @@ public function testNullableTypeCoercion(string $type, $value): void

$this->assertNull($converter->fromPayload($payload, $type));
}

/**
* DataConverter may decode protobuf binary messages
*/
public function testProtobufBinaryDecoding(): void
{
$message = (new Test())->setValue('foo');
$payload = (new ProtoConverter())->toPayload($message);

$decoded = DataConverter::createDefault()->fromPayload($payload, Test::class);

self::assertEquals($message, $decoded);
}

/**
* DataConverter decodes Protobuf messages using ProtoJson converter
*/
public function testProtobufEncodingToJson(): void
{
$message = (new Test())->setValue('foo');
$payload = DataConverter::createDefault()->toPayload($message);

self::assertSame(EncodingKeys::METADATA_ENCODING_PROTOBUF_JSON, $payload->getMetadata()['encoding']);
}
}

0 comments on commit 6f70059

Please sign in to comment.