|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests\Feature; |
| 6 | + |
| 7 | +use Tests\Fixtures\TestParentSignalingChildViaSignal; |
| 8 | +use Tests\Fixtures\TestParentWorkflowSignalingChildDirectly; |
| 9 | +use Tests\Fixtures\TestParentWorkflowWithContextCheck; |
| 10 | +use Tests\Fixtures\TestParentWorkflowWithMultipleChildren; |
| 11 | +use Tests\TestCase; |
| 12 | +use Workflow\States\WorkflowCompletedStatus; |
| 13 | +use Workflow\WorkflowStub; |
| 14 | + |
| 15 | +final class ChildWorkflowSignalingTest extends TestCase |
| 16 | +{ |
| 17 | + public function testParentCanSignalChildDirectly(): void |
| 18 | + { |
| 19 | + $parentWorkflow = WorkflowStub::make(TestParentWorkflowSignalingChildDirectly::class); |
| 20 | + $parentWorkflow->start(); |
| 21 | + |
| 22 | + while ($parentWorkflow->running()); |
| 23 | + |
| 24 | + $this->assertSame(WorkflowCompletedStatus::class, $parentWorkflow->status()); |
| 25 | + $this->assertSame('direct_signaling_approved', $parentWorkflow->output()); |
| 26 | + } |
| 27 | + |
| 28 | + public function testParentContextNotCorruptedByChildSignaling(): void |
| 29 | + { |
| 30 | + $parentWorkflow = WorkflowStub::make(TestParentWorkflowWithContextCheck::class); |
| 31 | + $parentWorkflow->start(); |
| 32 | + |
| 33 | + while ($parentWorkflow->running()); |
| 34 | + |
| 35 | + $this->assertSame(WorkflowCompletedStatus::class, $parentWorkflow->status()); |
| 36 | + $this->assertSame('success', $parentWorkflow->output()); |
| 37 | + } |
| 38 | + |
| 39 | + public function testParentSignalMethodForwardsToChild(): void |
| 40 | + { |
| 41 | + $parentWorkflow = WorkflowStub::make(TestParentSignalingChildViaSignal::class); |
| 42 | + $parentWorkflow->start(); |
| 43 | + |
| 44 | + sleep(3); |
| 45 | + |
| 46 | + $parentWorkflow->forwardApproval('approved'); |
| 47 | + |
| 48 | + $timeout = 10; |
| 49 | + while ($parentWorkflow->running() && $timeout-- > 0) { |
| 50 | + sleep(1); |
| 51 | + } |
| 52 | + |
| 53 | + $this->assertSame(WorkflowCompletedStatus::class, $parentWorkflow->status()); |
| 54 | + $this->assertSame('forwarded_approved', $parentWorkflow->output()); |
| 55 | + } |
| 56 | + |
| 57 | + public function testChildrenReturnsMultipleHandlesInOrder(): void |
| 58 | + { |
| 59 | + $parentWorkflow = WorkflowStub::make(TestParentWorkflowWithMultipleChildren::class); |
| 60 | + $parentWorkflow->start(); |
| 61 | + |
| 62 | + while ($parentWorkflow->running()); |
| 63 | + |
| 64 | + $this->assertSame(WorkflowCompletedStatus::class, $parentWorkflow->status()); |
| 65 | + $this->assertSame('child1_first|child2_second|child3_third', $parentWorkflow->output()); |
| 66 | + } |
| 67 | +} |
0 commit comments