From dd420a7fffdc834b79af6c3d38215dbfac156c14 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 31 Dec 2024 02:04:01 +0400 Subject: [PATCH] Prepare test environment --- src/Common/TypedSearchAttributes.php | 9 ++- src/Workflow.php | 6 +- testing/src/Environment.php | 2 - .../App/Runtime/TemporalStarter.php | 6 +- .../Workflow/TypedSearchAttributesTest.php | 55 +++++++++++++++++++ 5 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php diff --git a/src/Common/TypedSearchAttributes.php b/src/Common/TypedSearchAttributes.php index 65e30427..69fc9824 100644 --- a/src/Common/TypedSearchAttributes.php +++ b/src/Common/TypedSearchAttributes.php @@ -60,7 +60,7 @@ public static function fromJsonArray(array $array): self */ public function get(SearchAttributeKey $key): mixed { - $found = $this->findByName($key->getName()); + $found = $this->getByName($key->getName()); return match (true) { $found === null => null, @@ -71,7 +71,7 @@ public function get(SearchAttributeKey $key): mixed public function hasKey(SearchAttributeKey $key): bool { - return $this->findByName($key->getName()) !== null; + return $this->getByName($key->getName()) !== null; } public function withValue(SearchAttributeKey $key, mixed $value): self {} @@ -86,7 +86,10 @@ public function count(): int return $count; } - private function findByName(string $name): ?SearchAttributeKey + /** + * @param non-empty-string $name + */ + public function getByName(string $name): ?SearchAttributeKey { foreach ($this->collection ?? [] as $item) { if ($item->getName() === $name) { diff --git a/src/Workflow.php b/src/Workflow.php index 51c71ef7..0af4121b 100644 --- a/src/Workflow.php +++ b/src/Workflow.php @@ -889,7 +889,7 @@ public static function getStackTrace(): string * interruption of in-progress handlers by workflow exit: * * ```php - * yield Workflow.await(static fn() => Workflow::allHandlersFinished()); + * yield Workflow.await(static fn() => Workflow::allHandlersFinished()); * ``` * * @return bool True if all handlers have finished executing. @@ -957,8 +957,8 @@ public static function uuid4(): PromiseInterface * Generate a UUID version 7 (Unix Epoch time). * * @param \DateTimeInterface|null $dateTime An optional date/time from which - * to create the version 7 UUID. If not provided, the UUID is generated - * using the current date/time. + * to create the version 7 UUID. If not provided, the UUID is generated + * using the current date/time. * * @return PromiseInterface */ diff --git a/testing/src/Environment.php b/testing/src/Environment.php index 8adccdab..6687b600 100644 --- a/testing/src/Environment.php +++ b/testing/src/Environment.php @@ -67,8 +67,6 @@ public function startTemporalServer(int $commandTimeout = 10, array $parameters '--dynamic-config-value', 'frontend.enableUpdateWorkflowExecutionAsyncAccepted=true', '--dynamic-config-value', 'frontend.enableExecuteMultiOperation=true', '--dynamic-config-value', 'system.enableEagerWorkflowStart=true', - '--search-attribute', 'foo=text', - '--search-attribute', 'bar=int', '--log-level', 'error', '--headless', ...$parameters, diff --git a/tests/Acceptance/App/Runtime/TemporalStarter.php b/tests/Acceptance/App/Runtime/TemporalStarter.php index c684794f..4514dcda 100644 --- a/tests/Acceptance/App/Runtime/TemporalStarter.php +++ b/tests/Acceptance/App/Runtime/TemporalStarter.php @@ -23,7 +23,11 @@ public function start(): void return; } - $this->environment->startTemporalServer(); + $this->environment->startTemporalServer(parameters: [ + '--search-attribute', 'foo=text', + '--search-attribute', 'bar=int', + '--search-attribute', 'testFloat=double', + ]); $this->started = true; } diff --git a/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php b/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php new file mode 100644 index 00000000..000f2c80 --- /dev/null +++ b/tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php @@ -0,0 +1,55 @@ + $this->exit, + ); + + return Workflow::getInfo()->searchAttributes; + } + + #[Workflow\SignalMethod] + public function setAttributes(array $searchAttributes): void + { + $updates = []; + foreach ($searchAttributes as $name => $value) { + $updates[] = Workflow::getInfo()->typedSearchAttributes->getByName($name)->valueSet($value); + } + + Workflow::upsertTypedSearchAttributes(...$updates); + } + + #[Workflow\SignalMethod] + public function exit(): void + { + $this->exit = true; + } +}