|
9 | 9 | use Tests\Fixtures\V2\TestAliasedUpdateWorkflow; |
10 | 10 | use Tests\Fixtures\V2\TestChildHandleParentWorkflow; |
11 | 11 | use Tests\Fixtures\V2\TestSignalThenUpdateWorkflow; |
| 12 | +use Tests\Fixtures\V2\TestStartBoundaryReceiverWorkflow; |
12 | 13 | use Tests\Fixtures\V2\TestUpdateWorkflow; |
13 | 14 | use Tests\TestCase; |
14 | 15 | use Workflow\Serializers\Serializer; |
|
33 | 34 |
|
34 | 35 | final class V2UpdateWorkflowTest extends TestCase |
35 | 36 | { |
| 37 | + public function testStartBoundarySignalAndUpdateApplyAfterWorkflowInitialization(): void |
| 38 | + { |
| 39 | + Queue::fake(); |
| 40 | + |
| 41 | + $workflow = WorkflowStub::make(TestStartBoundaryReceiverWorkflow::class, 'start-boundary-receivers'); |
| 42 | + $workflow->start(); |
| 43 | + |
| 44 | + $runId = $workflow->runId(); |
| 45 | + |
| 46 | + $this->assertNotNull($runId); |
| 47 | + $this->assertSame(['StartAccepted', 'WorkflowStarted'], WorkflowHistoryEvent::query() |
| 48 | + ->where('workflow_run_id', $runId) |
| 49 | + ->orderBy('sequence') |
| 50 | + ->pluck('event_type') |
| 51 | + ->map(static fn ($eventType) => $eventType->value) |
| 52 | + ->all()); |
| 53 | + |
| 54 | + $update = $workflow->submitUpdate('approve', true, 'api'); |
| 55 | + $signal = $workflow->signal('name-provided', 'Taylor'); |
| 56 | + |
| 57 | + $this->assertTrue($update->accepted()); |
| 58 | + $this->assertFalse($update->completed()); |
| 59 | + $this->assertTrue($signal->accepted()); |
| 60 | + $this->assertSame('signal_received', $signal->outcome()); |
| 61 | + |
| 62 | + $this->runReadyWorkflowTask($runId); |
| 63 | + |
| 64 | + $this->waitFor(static fn (): bool => $workflow->refresh()->completed()); |
| 65 | + |
| 66 | + $this->assertSame([ |
| 67 | + 'stage' => 'completed', |
| 68 | + 'events' => ['initialized', 'update:yes:api:initialized', 'signal:Taylor:completed'], |
| 69 | + 'workflow_id' => 'start-boundary-receivers', |
| 70 | + 'run_id' => $runId, |
| 71 | + ], $workflow->output()); |
| 72 | + |
| 73 | + $this->assertDatabaseHas('workflow_updates', [ |
| 74 | + 'id' => $update->updateId(), |
| 75 | + 'workflow_run_id' => $runId, |
| 76 | + 'status' => 'completed', |
| 77 | + 'outcome' => 'update_completed', |
| 78 | + 'workflow_sequence' => 1, |
| 79 | + ]); |
| 80 | + |
| 81 | + $this->assertSame([ |
| 82 | + 'StartAccepted', |
| 83 | + 'WorkflowStarted', |
| 84 | + 'UpdateAccepted', |
| 85 | + 'SignalReceived', |
| 86 | + 'UpdateApplied', |
| 87 | + 'UpdateCompleted', |
| 88 | + 'MessageCursorAdvanced', |
| 89 | + 'SignalWaitOpened', |
| 90 | + 'MessageCursorAdvanced', |
| 91 | + 'SignalApplied', |
| 92 | + 'WorkflowCompleted', |
| 93 | + ], WorkflowHistoryEvent::query() |
| 94 | + ->where('workflow_run_id', $runId) |
| 95 | + ->orderBy('sequence') |
| 96 | + ->pluck('event_type') |
| 97 | + ->map(static fn ($eventType) => $eventType->value) |
| 98 | + ->all()); |
| 99 | + } |
| 100 | + |
36 | 101 | public function testAttemptUpdateUsesDeclaredAliasAsTheDurableTarget(): void |
37 | 102 | { |
38 | 103 | $workflow = WorkflowStub::make(TestAliasedUpdateWorkflow::class, 'order-update-alias'); |
|
0 commit comments