|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Temporal\Tests\Acceptance\Extra\Workflow\WorkflowInfo; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\Test; |
| 8 | +use Temporal\Client\WorkflowStubInterface; |
| 9 | +use Temporal\Tests\Acceptance\App\Attribute\RetryOptions; |
| 10 | +use Temporal\Tests\Acceptance\App\Attribute\Stub; |
| 11 | +use Temporal\Tests\Acceptance\App\TestCase; |
| 12 | +use Temporal\Workflow; |
| 13 | +use Temporal\Workflow\WorkflowInterface; |
| 14 | +use Temporal\Workflow\WorkflowMethod; |
| 15 | + |
| 16 | +class WorkflowInfoTest extends TestCase |
| 17 | +{ |
| 18 | + #[Test] |
| 19 | + public static function rootWorkflowExecution( |
| 20 | + #[Stub('Extra_Workflow_WorkflowInfo', args: [MainWorkflow::ARG_ROOT_EXECUTION])] |
| 21 | + WorkflowStubInterface $stub, |
| 22 | + ): void { |
| 23 | + $result = $stub->getResult(type: 'array'); |
| 24 | + self::assertSame([ |
| 25 | + 'ID' => $stub->getExecution()->getID(), |
| 26 | + 'RunID' => $stub->getExecution()->getRunID(), |
| 27 | + ], $result); |
| 28 | + } |
| 29 | + |
| 30 | + #[Test] |
| 31 | + public static function retryOptions( |
| 32 | + #[Stub('Extra_Workflow_WorkflowInfo', args: [MainWorkflow::ARG_RETRY_OPTIONS], retryOptions: new RetryOptions( |
| 33 | + backoffCoefficient: 3.0, |
| 34 | + maximumInterval: '2 minutes', |
| 35 | + maximumAttempts: 10, |
| 36 | + ))] |
| 37 | + WorkflowStubInterface $stub, |
| 38 | + ): void { |
| 39 | + $result = $stub->getResult(type: 'array'); |
| 40 | + self::assertEquals([ |
| 41 | + "initial_interval" => ['seconds' => 1, 'nanos' => 0], |
| 42 | + "backoff_coefficient" => 3, |
| 43 | + "maximum_interval" => ['seconds' => 120, 'nanos' => 0], |
| 44 | + "maximum_attempts" => 10, |
| 45 | + "non_retryable_error_types" => [], |
| 46 | + ], $result); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +#[WorkflowInterface] |
| 51 | +class MainWorkflow |
| 52 | +{ |
| 53 | + public const ARG_RETRY_OPTIONS = 'retryPolicy'; |
| 54 | + public const ARG_ROOT_EXECUTION = 'rootExecution'; |
| 55 | + |
| 56 | + #[WorkflowMethod('Extra_Workflow_WorkflowInfo')] |
| 57 | + public function run($arg) |
| 58 | + { |
| 59 | + return yield match ($arg) { |
| 60 | + self::ARG_ROOT_EXECUTION => Workflow::newChildWorkflowStub(ChildWorkflow::class)->run(), |
| 61 | + self::ARG_RETRY_OPTIONS => Workflow::getCurrentContext()->getInfo()->retryOptions, |
| 62 | + }; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +#[WorkflowInterface] |
| 67 | +class ChildWorkflow |
| 68 | +{ |
| 69 | + #[WorkflowMethod('Extra_Workflow_WorkflowInfo_Child')] |
| 70 | + public function run() |
| 71 | + { |
| 72 | + return yield Workflow::newChildWorkflowStub(ChildWorkflow2::class)->run(); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +#[WorkflowInterface] |
| 77 | +class ChildWorkflow2 |
| 78 | +{ |
| 79 | + #[WorkflowMethod('Extra_Workflow_WorkflowInfo_Child2')] |
| 80 | + public function run() |
| 81 | + { |
| 82 | + return Workflow::getCurrentContext()->getInfo()->rootExecution; |
| 83 | + } |
| 84 | +} |
0 commit comments