Skip to content

Commit

Permalink
Prepare test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 30, 2024
1 parent 0b021da commit dd420a7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/Common/TypedSearchAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {}
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<UuidInterface>
*/
Expand Down
2 changes: 0 additions & 2 deletions testing/src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion tests/Acceptance/App/Runtime/TemporalStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
55 changes: 55 additions & 0 deletions tests/Acceptance/Extra/Workflow/TypedSearchAttributesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Acceptance\Extra\Workflow\TypedSearchAttributes;

use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\Test;
use Temporal\Client\WorkflowClientInterface;
use Temporal\Client\WorkflowOptions;
use Temporal\Common\SearchAttributes\SearchAttributeKey;
use Temporal\Common\TypedSearchAttributes;
use Temporal\Tests\Acceptance\App\Runtime\Feature;
use Temporal\Tests\Acceptance\App\TestCase;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[CoversFunction('Temporal\Internal\Workflow\Process\Process::logRunningHandlers')]
class TypedSearchAttributesTest extends TestCase
{
}

#[WorkflowInterface]
class TestWorkflow
{
private bool $exit = false;

#[WorkflowMethod(name: "Extra_Workflow_TypedSearchAttributes")]
public function handle()
{
yield Workflow::await(
fn(): bool => $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;
}
}

0 comments on commit dd420a7

Please sign in to comment.