Skip to content

Commit ceda125

Browse files
Test start-boundary receiver ordering
1 parent 3ffda1e commit ceda125

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

tests/Feature/V2/V2UpdateWorkflowTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Tests\Fixtures\V2\TestAliasedUpdateWorkflow;
1010
use Tests\Fixtures\V2\TestChildHandleParentWorkflow;
1111
use Tests\Fixtures\V2\TestSignalThenUpdateWorkflow;
12+
use Tests\Fixtures\V2\TestStartBoundaryReceiverWorkflow;
1213
use Tests\Fixtures\V2\TestUpdateWorkflow;
1314
use Tests\TestCase;
1415
use Workflow\Serializers\Serializer;
@@ -33,6 +34,70 @@
3334

3435
final class V2UpdateWorkflowTest extends TestCase
3536
{
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+
36101
public function testAttemptUpdateUsesDeclaredAliasAsTheDurableTarget(): void
37102
{
38103
$workflow = WorkflowStub::make(TestAliasedUpdateWorkflow::class, 'order-update-alias');
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Fixtures\V2;
6+
7+
use Workflow\UpdateMethod;
8+
use Workflow\V2\Attributes\Signal;
9+
use Workflow\V2\Attributes\Type;
10+
use function Workflow\V2\signal;
11+
use Workflow\V2\Workflow;
12+
13+
#[Type('test-start-boundary-receiver-workflow')]
14+
#[Signal('name-provided')]
15+
final class TestStartBoundaryReceiverWorkflow extends Workflow
16+
{
17+
private string $stage = 'booting';
18+
19+
/**
20+
* @var list<string>
21+
*/
22+
private array $events = [];
23+
24+
public function handle(): array
25+
{
26+
$this->stage = 'initialized';
27+
$this->events[] = 'initialized';
28+
29+
$name = signal('name-provided');
30+
31+
$this->stage = 'completed';
32+
$this->events[] = sprintf('signal:%s:%s', $name, $this->stage);
33+
34+
return [
35+
'stage' => $this->stage,
36+
'events' => $this->events,
37+
'workflow_id' => $this->workflowId(),
38+
'run_id' => $this->runId(),
39+
];
40+
}
41+
42+
#[UpdateMethod]
43+
public function approve(bool $approved, string $source = 'manual'): array
44+
{
45+
$this->events[] = sprintf('update:%s:%s:%s', $approved ? 'yes' : 'no', $source, $this->stage);
46+
47+
return [
48+
'stage' => $this->stage,
49+
'events' => $this->events,
50+
];
51+
}
52+
}

0 commit comments

Comments
 (0)