Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Feb 10, 2025
1 parent 262f4a9 commit 2efec4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/Unit/DTO/Type/DurationJsonType/DurationJsonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,25 @@ class DurationJsonTestCase extends AbstractDTOMarshalling
public function testMarshalAndUnmarshalDuration(): void
{
$dto = new DurationJsonDto();
$dto->duration = DateInterval::parse(1);
$dto->duration = DateInterval::parse(100);
$dto->durationProto = DateInterval::parse(12000);

$result = $this->marshal($dto);
$unmarshal = $this->unmarshal($result, new DurationJsonDto());

self::assertInstanceOf(\DateInterval::class, $unmarshal->duration);
self::assertInstanceOf(\DateInterval::class, $unmarshal->durationProto);
self::assertSame('0 100000', $unmarshal->duration->format('%s %f'));
self::assertSame('12 0', $unmarshal->durationProto->format('%s %f'));
}

public function testUnmarshallEmptyDuration(): void
{
$result = ['duration' => null, 'duration_proto' => null];
$unmarshal = $this->unmarshal($result, new DurationJsonDto());

self::assertSame('0.0', $unmarshal->duration->format('%s.%f'));
self::assertSame('0.0', $unmarshal->durationProto->format('%s.%f'));
}

protected function getTypeMatchers(): array
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/DTO/Type/DurationJsonType/Stub/DurationJsonDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

namespace Temporal\Tests\Unit\DTO\Type\DurationJsonType\Stub;

use Google\Protobuf\Duration;
use Temporal\Internal\Marshaller\Meta\Marshal;

class DurationJsonDto
{
public \DateInterval $duration;

#[Marshal('duration_proto', of: Duration::class)]
public \DateInterval $durationProto;
}

0 comments on commit 2efec4a

Please sign in to comment.