@@ -17,23 +17,59 @@ class WorkflowInfoTest extends TestCase
1717{
1818 #[Test]
1919 public static function rootWorkflowExecution (
20- #[Stub('Extra_Workflow_WorkflowInfo ' , args: [MainWorkflow::ARG_ROOT_EXECUTION ])]
20+ #[Stub('Extra_Workflow_WorkflowInfo ' , args: [[ MainWorkflow::ARG_ROOT_EXECUTION ] ])]
2121 WorkflowStubInterface $ stub ,
2222 ): void {
2323 $ result = $ stub ->getResult (type: 'array ' );
2424 self ::assertSame ([
25- 'ID ' => $ stub ->getExecution ()->getID (),
26- 'RunID ' => $ stub ->getExecution ()->getRunID (),
27- ], $ result );
25+ 'id ' => $ stub ->getExecution ()->getID (),
26+ 'runID ' => $ stub ->getExecution ()->getRunID (),
27+ ], $ result ['rootExecution ' ]);
28+ }
29+
30+ #[Test]
31+ public static function continueAsNewExecution (
32+ #[Stub('Extra_Workflow_WorkflowInfo ' , args: [[
33+ MainWorkflow::ARG_CONTINUE_AS_NEW ,
34+ MainWorkflow::ARG_DUMP ,
35+ ]])]
36+ WorkflowStubInterface $ stub ,
37+ ): void {
38+ $ result = $ stub ->getResult (type: 'array ' );
39+ self ::assertNotEmpty ($ result ['continuedExecutionRunId ' ]);
40+ self ::assertSame ($ result ['firstExecutionRunId ' ], $ result ['continuedExecutionRunId ' ]);
41+ self ::assertNotSame ($ result ['firstExecutionRunId ' ], $ result ['originalExecutionRunId ' ]);
42+ }
43+
44+ #[Test]
45+ public static function continueAsNewExecutionChild (
46+ #[Stub('Extra_Workflow_WorkflowInfo ' , args: [[
47+ MainWorkflow::ARG_CONTINUE_AS_NEW ,
48+ MainWorkflow::ARG_RUN_MAIN_AS_CHILD ,
49+ MainWorkflow::ARG_DUMP ,
50+ ]])]
51+ WorkflowStubInterface $ stub ,
52+ ): void {
53+ $ result = $ stub ->getResult (type: 'array ' );
54+ /**
55+ * There is no information about continued execution in child workflows.
56+ */
57+ self ::assertEmpty ($ result ['continuedExecutionRunId ' ]);
58+ self ::assertIsString ($ result ['continuedExecutionRunId ' ]);
59+ self ::assertSame ($ result ['firstExecutionRunId ' ], $ result ['originalExecutionRunId ' ]);
2860 }
2961
3062 #[Test]
3163 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- ))]
64+ #[Stub(
65+ 'Extra_Workflow_WorkflowInfo ' ,
66+ args: [[MainWorkflow::ARG_RETRY_OPTIONS ]],
67+ retryOptions: new RetryOptions (
68+ backoffCoefficient: 3.0 ,
69+ maximumInterval: '2 minutes ' ,
70+ maximumAttempts: 10 ,
71+ ),
72+ )]
3773 WorkflowStubInterface $ stub ,
3874 ): void {
3975 $ result = $ stub ->getResult (type: 'array ' );
@@ -52,13 +88,20 @@ class MainWorkflow
5288{
5389 public const ARG_RETRY_OPTIONS = 'retryPolicy ' ;
5490 public const ARG_ROOT_EXECUTION = 'rootExecution ' ;
91+ public const ARG_CONTINUE_AS_NEW = 'continueAsNew ' ;
92+ public const ARG_DUMP = 'dump ' ;
93+ public const ARG_RUN_MAIN_AS_CHILD = 'runMainAsChild ' ;
5594
5695 #[WorkflowMethod('Extra_Workflow_WorkflowInfo ' )]
57- public function run ($ arg )
96+ public function run (array $ actions )
5897 {
59- return yield match ($ arg ) {
98+ $ action = \array_shift ($ actions );
99+ return yield match ($ action ) {
60100 self ::ARG_ROOT_EXECUTION => Workflow::newChildWorkflowStub (ChildWorkflow::class)->run (),
61- self ::ARG_RETRY_OPTIONS => Workflow::getCurrentContext ()->getInfo ()->retryOptions ,
101+ self ::ARG_RETRY_OPTIONS => Workflow::getInfo ()->retryOptions ,
102+ self ::ARG_CONTINUE_AS_NEW => Workflow::continueAsNew ('Extra_Workflow_WorkflowInfo ' , args: [$ actions ]),
103+ self ::ARG_RUN_MAIN_AS_CHILD => Workflow::newChildWorkflowStub (MainWorkflow::class)->run ($ actions ),
104+ self ::ARG_DUMP => Helper::dumpWorkflow (),
62105 };
63106 }
64107}
@@ -79,6 +122,23 @@ class ChildWorkflow2
79122 #[WorkflowMethod('Extra_Workflow_WorkflowInfo_Child2 ' )]
80123 public function run ()
81124 {
82- return Workflow::getCurrentContext ()->getInfo ()->rootExecution ;
125+ return Helper::dumpWorkflow ();
126+ }
127+ }
128+
129+ class Helper
130+ {
131+ public static function dumpWorkflow (): array
132+ {
133+ $ workflowInfo = Workflow::getInfo ();
134+ return [
135+ 'rootExecution ' => [
136+ 'id ' => $ workflowInfo ->rootExecution ?->getID(),
137+ 'runID ' => $ workflowInfo ->rootExecution ?->getRunID(),
138+ ],
139+ 'firstExecutionRunId ' => $ workflowInfo ->firstExecutionRunId ,
140+ 'continuedExecutionRunId ' => $ workflowInfo ->continuedExecutionRunId ,
141+ 'originalExecutionRunId ' => $ workflowInfo ->originalExecutionRunId ,
142+ ];
83143 }
84144}
0 commit comments