|
9 | 9 | use Symfony\Component\Filesystem\Filesystem; |
10 | 10 | use Symfony\Component\HttpClient\HttpClient; |
11 | 11 | use Symfony\Component\Process\Process; |
| 12 | +use Temporal\Common\SearchAttributes\ValueType; |
12 | 13 |
|
13 | 14 | final class Environment |
14 | 15 | { |
@@ -52,11 +53,41 @@ public function start(?string $rrCommand = null, int $commandTimeout = 10, array |
52 | 53 |
|
53 | 54 | /** |
54 | 55 | * @param list<non-empty-string> $parameters |
| 56 | + * @param array<non-empty-string, ValueType|non-empty-string> $searchAttributes Key is the name of the search |
| 57 | + * attribute, value is the type of the search attribute. Expected values from {@see ValueType}. |
55 | 58 | */ |
56 | | - public function startTemporalServer(int $commandTimeout = 10, array $parameters = []): void |
57 | | - { |
| 59 | + public function startTemporalServer( |
| 60 | + int $commandTimeout = 10, |
| 61 | + array $parameters = [], |
| 62 | + array $searchAttributes = [], |
| 63 | + ): void { |
58 | 64 | $temporalPort = \parse_url(\getenv('TEMPORAL_ADDRESS') ?: '127.0.0.1:7233', PHP_URL_PORT); |
59 | 65 |
|
| 66 | + // Add search attributes |
| 67 | + foreach ($searchAttributes as $name => $type) { |
| 68 | + $type = \is_string($type) ? ValueType::tryFrom($type) : $type; |
| 69 | + if (!$type instanceof ValueType) { |
| 70 | + \trigger_error('Invalid search attribute type: ' . \get_debug_type($type), E_USER_WARNING); |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
| 74 | + if (\preg_match('/^[a-zA-Z0-9_-]+$/', $name) !== 1) { |
| 75 | + \trigger_error('Invalid search attribute name: ' . $name, E_USER_WARNING); |
| 76 | + continue; |
| 77 | + } |
| 78 | + |
| 79 | + $parameters[] = '--search-attribute'; |
| 80 | + $parameters[] = $name . '=' . match ($type) { |
| 81 | + ValueType::Bool => 'bool', |
| 82 | + ValueType::Float => 'double', |
| 83 | + ValueType::Int => 'int', |
| 84 | + ValueType::Keyword => 'keyword', |
| 85 | + ValueType::KeywordList => 'keywordList', |
| 86 | + ValueType::String => 'text', |
| 87 | + ValueType::Datetime => 'datetime', |
| 88 | + }; |
| 89 | + } |
| 90 | + |
60 | 91 | $this->output->write('Starting Temporal test server... '); |
61 | 92 | $this->temporalServerProcess = new Process( |
62 | 93 | [ |
|
0 commit comments