|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\Attributes\Test; |
8 | 8 | use Ramsey\Uuid\Uuid; |
| 9 | +use Temporal\Client\Update\LifecycleStage; |
| 10 | +use Temporal\Client\Update\UpdateOptions; |
9 | 11 | use Temporal\Client\WorkflowClientInterface; |
10 | 12 | use Temporal\Client\WorkflowOptions; |
11 | 13 | use Temporal\Exception\Client\WorkflowExecutionAlreadyStartedException; |
12 | 14 | use Temporal\Exception\Client\WorkflowFailedException; |
| 15 | +use Temporal\Exception\Client\WorkflowServiceException; |
13 | 16 | use Temporal\Exception\Client\WorkflowUpdateException; |
14 | 17 | use Temporal\Tests\Acceptance\App\Runtime\Feature; |
15 | 18 | use Temporal\Tests\Acceptance\App\TestCase; |
@@ -41,6 +44,49 @@ public function runInGoodWay( |
41 | 44 | $this->assertFalse($handle->hasResult()); |
42 | 45 | } |
43 | 46 |
|
| 47 | + #[Test] |
| 48 | + public function returnsTypedUpdateResult( |
| 49 | + WorkflowClientInterface $client, |
| 50 | + Feature $feature, |
| 51 | + ): void { |
| 52 | + $stub = $client->newUntypedWorkflowStub( |
| 53 | + 'Extra_Update_UpdateWithStart', |
| 54 | + WorkflowOptions::new()->withTaskQueue($feature->taskQueue), |
| 55 | + ); |
| 56 | + |
| 57 | + $options = UpdateOptions::new('echo', LifecycleStage::StageCompleted) |
| 58 | + ->withResultType(UpdateResult::class); |
| 59 | + |
| 60 | + /** @see TestWorkflow::echo */ |
| 61 | + $handle = $client->updateWithStart($stub, $options, ['hello']); |
| 62 | + |
| 63 | + $result = $handle->getResult(); |
| 64 | + $this->assertInstanceOf(UpdateResult::class, $result); |
| 65 | + $this->assertSame('hello', $result->name); |
| 66 | + $this->assertSame(5, $result->length); |
| 67 | + |
| 68 | + $stub->signal('exit'); |
| 69 | + $stub->getResult(); |
| 70 | + } |
| 71 | + |
| 72 | + #[Test] |
| 73 | + public function rejectsFirstExecutionRunId( |
| 74 | + WorkflowClientInterface $client, |
| 75 | + Feature $feature, |
| 76 | + ): void { |
| 77 | + $stub = $client->newUntypedWorkflowStub( |
| 78 | + 'Extra_Update_UpdateWithStart', |
| 79 | + WorkflowOptions::new()->withTaskQueue($feature->taskQueue), |
| 80 | + ); |
| 81 | + |
| 82 | + $options = UpdateOptions::new('await', LifecycleStage::StageAccepted) |
| 83 | + ->withFirstExecutionRunId(Uuid::uuid7()->__toString()); |
| 84 | + |
| 85 | + $this->expectException(WorkflowServiceException::class); |
| 86 | + $this->expectExceptionMessage('FirstExecutionRunId is not allowed'); |
| 87 | + $client->updateWithStart($stub, $options, ['key']); |
| 88 | + } |
| 89 | + |
44 | 90 | #[Test] |
45 | 91 | public function failWithBadUpdateName( |
46 | 92 | WorkflowClientInterface $client, |
@@ -128,9 +174,24 @@ public function validateAdd(string $name): void |
128 | 174 | empty($name) and throw new \InvalidArgumentException('Name must not be empty'); |
129 | 175 | } |
130 | 176 |
|
| 177 | + #[Workflow\UpdateMethod(name: 'echo')] |
| 178 | + public function echo(string $name): UpdateResult |
| 179 | + { |
| 180 | + $this->updateStarted = true; |
| 181 | + return new UpdateResult($name, \strlen($name)); |
| 182 | + } |
| 183 | + |
131 | 184 | #[Workflow\SignalMethod] |
132 | 185 | public function exit(): void |
133 | 186 | { |
134 | 187 | $this->exit = true; |
135 | 188 | } |
136 | 189 | } |
| 190 | + |
| 191 | +class UpdateResult |
| 192 | +{ |
| 193 | + public function __construct( |
| 194 | + public string $name = '', |
| 195 | + public int $length = 0, |
| 196 | + ) {} |
| 197 | +} |
0 commit comments