-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathParentWorkflowTest.php
More file actions
112 lines (88 loc) · 3.55 KB
/
ParentWorkflowTest.php
File metadata and controls
112 lines (88 loc) · 3.55 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Tests\Fixtures\TestActivity;
use Tests\Fixtures\TestChildExceptionWorkflow;
use Tests\Fixtures\TestChildTimerWorkflow;
use Tests\Fixtures\TestChildWorkflow;
use Tests\Fixtures\TestParentAsyncWorkflow;
use Tests\Fixtures\TestParentExceptionWorkflow;
use Tests\Fixtures\TestParentTimerWorkflow;
use Tests\Fixtures\TestParentWorkflow;
use Tests\TestCase;
use Workflow\AsyncWorkflow;
use Workflow\Models\StoredWorkflow;
use Workflow\States\WorkflowCompletedStatus;
use Workflow\States\WorkflowCreatedStatus;
use Workflow\States\WorkflowFailedStatus;
use Workflow\WorkflowStub;
final class ParentWorkflowTest extends TestCase
{
public function testCompleted(): void
{
$workflow = WorkflowStub::make(TestParentWorkflow::class);
$workflow->start();
while ($workflow->running());
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('workflow_activity_other', $workflow->output());
$this->assertSame([TestActivity::class, TestChildWorkflow::class], $workflow->logs()
->pluck('class')
->sort()
->values()
->toArray());
}
public function testRetry(): void
{
$workflow = WorkflowStub::make(TestParentExceptionWorkflow::class);
$workflow->start(shouldThrow: true);
while ($workflow->running());
$this->assertSame(WorkflowFailedStatus::class, $workflow->status());
$this->assertNull($workflow->output());
$storedWorkflow = StoredWorkflow::findOrFail($workflow->id());
$storedWorkflow->status = WorkflowCreatedStatus::class;
$storedWorkflow->save();
$storedWorkflow->logs()
->delete();
$storedWorkflow->exceptions()
->delete();
$storedChildWorkflow = StoredWorkflow::findOrFail($workflow->id() + 1);
$storedChildWorkflow->status = WorkflowCreatedStatus::class;
$storedChildWorkflow->save();
$storedChildWorkflow->logs()
->delete();
$storedChildWorkflow->exceptions()
->delete();
$workflow->fresh()
->start(shouldThrow: false);
while ($workflow->running());
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('workflow_activity_other', $workflow->output());
$this->assertSame([TestActivity::class, TestChildExceptionWorkflow::class], $workflow->logs()
->pluck('class')
->sort()
->values()
->toArray());
}
public function testTimer(): void
{
$workflow = WorkflowStub::make(TestParentTimerWorkflow::class);
$workflow->start(1);
while ($workflow->running());
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('workflow_activity_other', $workflow->output());
$this->assertSame([TestActivity::class, TestChildTimerWorkflow::class], $workflow->logs()
->pluck('class')
->sort()
->values()
->toArray());
}
public function testAsync(): void
{
$workflow = WorkflowStub::make(TestParentAsyncWorkflow::class);
$workflow->start();
while ($workflow->running());
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('workflow_activity_other', $workflow->output());
$this->assertSame([AsyncWorkflow::class], $workflow->logs()->pluck('class')->sort()->values()->toArray());
}
}