diff --git a/src/DataConverter/JsonConverter.php b/src/DataConverter/JsonConverter.php index 8f422e4d..a7d447d7 100644 --- a/src/DataConverter/JsonConverter.php +++ b/src/DataConverter/JsonConverter.php @@ -56,6 +56,7 @@ public function toPayload($value): ?Payload $value = match (true) { $value instanceof \stdClass => $value, $value instanceof UuidInterface => $value->toString(), + $value instanceof \DateTimeInterface => $value->format(\DateTimeInterface::RFC3339), default => $this->marshaller->marshal($value), }; } @@ -133,6 +134,11 @@ public function fromPayload(Payload $payload, Type $type) } return Uuid::fromString($data); + + case \DateTimeImmutable::class: + case \DateTimeInterface::class: + \is_string($data) or throw $this->errorInvalidType($type, $data); + return new \DateTimeImmutable($data); case Type::TYPE_OBJECT: if (!\is_object($data)) { throw $this->errorInvalidType($type, $data); diff --git a/tests/Acceptance/App/Runtime/TemporalStarter.php b/tests/Acceptance/App/Runtime/TemporalStarter.php index 8ce4749f..3f61fe13 100644 --- a/tests/Acceptance/App/Runtime/TemporalStarter.php +++ b/tests/Acceptance/App/Runtime/TemporalStarter.php @@ -26,10 +26,13 @@ public function start(): void $this->environment->startTemporalServer(parameters: [ '--search-attribute', 'foo=text', '--search-attribute', 'bar=int', + '--search-attribute', 'testBool=bool', '--search-attribute', 'testInt=int', '--search-attribute', 'testFloat=double', '--search-attribute', 'testString=text', '--search-attribute', 'testKeyword=keyword', + '--search-attribute', 'testKeywordList=keywordList', + '--search-attribute', 'testDatetime=datetime', ]); $this->started = true; } diff --git a/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php b/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php index 9ea677a7..7b879b37 100644 --- a/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php +++ b/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php @@ -31,6 +31,15 @@ public function testStartWithTypedSearchAttributes( ->withTypedSearchAttributes( TypedSearchAttributes::empty() ->withValue(SearchAttributeKey::forFloat('testFloat'), 1.1) + ->withValue(SearchAttributeKey::forInteger('testInt'), -2) + ->withValue(SearchAttributeKey::forBool('testBool'), false) + ->withValue(SearchAttributeKey::forString('testString'), 'foo') + ->withValue(SearchAttributeKey::forKeyword('testKeyword'), 'bar') + ->withValue(SearchAttributeKey::forKeywordList('testKeywordList'), ['baz']) + ->withValue( + SearchAttributeKey::forDatetime('testDatetime'), + new \DateTimeImmutable('2019-01-01T00:00:00Z'), + ) ), ); @@ -42,7 +51,16 @@ public function testStartWithTypedSearchAttributes( $stub->signal('exit'); $result = $stub->getResult(); - $this->assertSame(['testFloat' => 1.1], (array)$result); + $this->assertEquals([ + 'testBool' => false, + 'testInt' => -2, + 'testFloat' => 1.1, + 'testString' => 'foo', + 'testKeyword' => 'bar', + 'testKeywordList' => ['baz'], + 'testDatetime' => (new \DateTimeImmutable('2019-01-01T00:00:00Z')) + ->format(\DateTimeInterface::RFC3339), + ], (array)$result); } #[Test] @@ -54,11 +72,26 @@ public function testUpsertTypedSearchAttributes( 'Extra_Workflow_TypedSearchAttributes', WorkflowOptions::new() ->withTaskQueue($feature->taskQueue) - ->withSearchAttributes(['testFloat' => 1.1]) + ->withSearchAttributes([ + 'testBool' => false, + 'testInt' => -2, + 'testFloat' => 1.1, + 'testString' => 'foo', + 'testKeyword' => 'bar', + 'testKeywordList' => ['baz'], + 'testDatetime' => (new \DateTimeImmutable('2019-01-01T00:00:00Z')) + ->format(\DateTimeInterface::RFC3339), + ]) ); $toSend = [ + 'testBool' => true, + 'testInt' => 42, 'testFloat' => 3.25, + 'testString' => 'foo bar baz', + 'testKeyword' => 'foo-bar-baz', + 'testKeywordList' => ['foo', 'bar', 'baz'], + 'testDatetime' => (new \DateTimeImmutable('2021-01-01T00:00:00Z'))->format(\DateTimeInterface::RFC3339), ]; /** @see TestWorkflow::handle() */