Skip to content

Commit dd420a7

Browse files
committed
Prepare test environment
1 parent 0b021da commit dd420a7

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

src/Common/TypedSearchAttributes.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function fromJsonArray(array $array): self
6060
*/
6161
public function get(SearchAttributeKey $key): mixed
6262
{
63-
$found = $this->findByName($key->getName());
63+
$found = $this->getByName($key->getName());
6464

6565
return match (true) {
6666
$found === null => null,
@@ -71,7 +71,7 @@ public function get(SearchAttributeKey $key): mixed
7171

7272
public function hasKey(SearchAttributeKey $key): bool
7373
{
74-
return $this->findByName($key->getName()) !== null;
74+
return $this->getByName($key->getName()) !== null;
7575
}
7676

7777
public function withValue(SearchAttributeKey $key, mixed $value): self {}
@@ -86,7 +86,10 @@ public function count(): int
8686
return $count;
8787
}
8888

89-
private function findByName(string $name): ?SearchAttributeKey
89+
/**
90+
* @param non-empty-string $name
91+
*/
92+
public function getByName(string $name): ?SearchAttributeKey
9093
{
9194
foreach ($this->collection ?? [] as $item) {
9295
if ($item->getName() === $name) {

src/Workflow.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ public static function getStackTrace(): string
889889
* interruption of in-progress handlers by workflow exit:
890890
*
891891
* ```php
892-
* yield Workflow.await(static fn() => Workflow::allHandlersFinished());
892+
* yield Workflow.await(static fn() => Workflow::allHandlersFinished());
893893
* ```
894894
*
895895
* @return bool True if all handlers have finished executing.
@@ -957,8 +957,8 @@ public static function uuid4(): PromiseInterface
957957
* Generate a UUID version 7 (Unix Epoch time).
958958
*
959959
* @param \DateTimeInterface|null $dateTime An optional date/time from which
960-
* to create the version 7 UUID. If not provided, the UUID is generated
961-
* using the current date/time.
960+
* to create the version 7 UUID. If not provided, the UUID is generated
961+
* using the current date/time.
962962
*
963963
* @return PromiseInterface<UuidInterface>
964964
*/

testing/src/Environment.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public function startTemporalServer(int $commandTimeout = 10, array $parameters
6767
'--dynamic-config-value', 'frontend.enableUpdateWorkflowExecutionAsyncAccepted=true',
6868
'--dynamic-config-value', 'frontend.enableExecuteMultiOperation=true',
6969
'--dynamic-config-value', 'system.enableEagerWorkflowStart=true',
70-
'--search-attribute', 'foo=text',
71-
'--search-attribute', 'bar=int',
7270
'--log-level', 'error',
7371
'--headless',
7472
...$parameters,

tests/Acceptance/App/Runtime/TemporalStarter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public function start(): void
2323
return;
2424
}
2525

26-
$this->environment->startTemporalServer();
26+
$this->environment->startTemporalServer(parameters: [
27+
'--search-attribute', 'foo=text',
28+
'--search-attribute', 'bar=int',
29+
'--search-attribute', 'testFloat=double',
30+
]);
2731
$this->started = true;
2832
}
2933

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Tests\Acceptance\Extra\Workflow\TypedSearchAttributes;
6+
7+
use PHPUnit\Framework\Attributes\CoversFunction;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use Temporal\Client\WorkflowClientInterface;
10+
use Temporal\Client\WorkflowOptions;
11+
use Temporal\Common\SearchAttributes\SearchAttributeKey;
12+
use Temporal\Common\TypedSearchAttributes;
13+
use Temporal\Tests\Acceptance\App\Runtime\Feature;
14+
use Temporal\Tests\Acceptance\App\TestCase;
15+
use Temporal\Workflow;
16+
use Temporal\Workflow\WorkflowInterface;
17+
use Temporal\Workflow\WorkflowMethod;
18+
19+
#[CoversFunction('Temporal\Internal\Workflow\Process\Process::logRunningHandlers')]
20+
class TypedSearchAttributesTest extends TestCase
21+
{
22+
}
23+
24+
#[WorkflowInterface]
25+
class TestWorkflow
26+
{
27+
private bool $exit = false;
28+
29+
#[WorkflowMethod(name: "Extra_Workflow_TypedSearchAttributes")]
30+
public function handle()
31+
{
32+
yield Workflow::await(
33+
fn(): bool => $this->exit,
34+
);
35+
36+
return Workflow::getInfo()->searchAttributes;
37+
}
38+
39+
#[Workflow\SignalMethod]
40+
public function setAttributes(array $searchAttributes): void
41+
{
42+
$updates = [];
43+
foreach ($searchAttributes as $name => $value) {
44+
$updates[] = Workflow::getInfo()->typedSearchAttributes->getByName($name)->valueSet($value);
45+
}
46+
47+
Workflow::upsertTypedSearchAttributes(...$updates);
48+
}
49+
50+
#[Workflow\SignalMethod]
51+
public function exit(): void
52+
{
53+
$this->exit = true;
54+
}
55+
}

0 commit comments

Comments
 (0)