-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathSagaWorkflowTest.php
More file actions
64 lines (49 loc) · 1.87 KB
/
SagaWorkflowTest.php
File metadata and controls
64 lines (49 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\Fixtures\TestActivity;
use Tests\Fixtures\TestSagaParallelActivityWorkflow;
use Tests\Fixtures\TestSagaWorkflow;
use Tests\Fixtures\TestUndoActivity;
use Tests\TestCase;
use Workflow\Exception;
use Workflow\States\WorkflowCompletedStatus;
use Workflow\States\WorkflowFailedStatus;
use Workflow\WorkflowStub;
final class SagaWorkflowTest extends TestCase
{
public function testCompleted(): void
{
$workflow = WorkflowStub::make(TestSagaWorkflow::class);
$workflow->start(shouldThrow: false);
while ($workflow->running());
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('saga_workflow', $workflow->output());
$this->assertSame([TestActivity::class, TestUndoActivity::class, Exception::class], $workflow->logs()
->pluck('class')
->sort()
->values()
->toArray());
}
public function testFailed(): void
{
$workflow = WorkflowStub::make(TestSagaWorkflow::class);
$workflow->start(shouldThrow: true);
while ($workflow->running());
$this->assertSame(WorkflowFailedStatus::class, $workflow->status());
$this->assertNull($workflow->output());
$this->assertSame([TestActivity::class, TestUndoActivity::class, Exception::class], $workflow->logs()
->pluck('class')
->sort()
->values()
->toArray());
}
public function testParallelActivityExceptionsTriggersCompensation(): void
{
$workflow = WorkflowStub::make(TestSagaParallelActivityWorkflow::class);
$workflow->start();
while ($workflow->running());
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('compensated', $workflow->output());
}
}