-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowModelTest.php
More file actions
127 lines (107 loc) · 2.55 KB
/
FlowModelTest.php
File metadata and controls
127 lines (107 loc) · 2.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace SyncEngine\Tests\Model;
use SyncEngine\Model\FlowModel;
use SyncEngine\Model\RoutineModel;
use SyncEngine\Service\ExecuteData;
use SyncEngine\Task\Set;
use SyncEngine\Tests\TestCase\ExecuteTestCase;
class FlowModelTest extends ExecuteTestCase
{
public function testSequenceBasic(): void
{
$flow = FlowModel::create();
/** @var FlowModel $flow */
$flow->setName('Test Basic Flow');
$routines = $this->getRoutines();
$flow->setConfig( [
'steps' => [
$routines['routine1']->getId(),
$routines['routine2']->getId(),
$routines['routine1']->getId(),
],
] );
$result = $this->getExecute()->executeFlow( $flow, $this->getContext(), ExecuteData::create() );
$this->assertEquals( 'routine_2', $result->get('done') );
}
public function testSequenceConfig(): void
{
$flow = FlowModel::create();
/** @var FlowModel $flow */
$flow->setName('Test Config Flow');
$routines = $this->getRoutines();
$flow->setConfig( [
'steps' => [
[
'routine' => $routines['routine1']->getId(),
'config' => [],
],
[
'routine' => $routines['routine2']->getId(),
'config' => [],
],
[
'routine' => $routines['routine1']->getId(),
'config' => [
'input' => [
'current' => 'step_3_routine_1',
]
],
],
],
] );
$result = $this->getExecute()->executeFlow( $flow, $this->getContext(), ExecuteData::create() );
$this->assertEquals( 'step_3_routine_1', $result->get('done') );
}
private function getRoutines(): array
{
static $routines = [];
if ( ! empty( $routines ) ) {
return $routines;
}
$routine1 = RoutineModel::create();
/** @var RoutineModel $routine1 */
$routine1->setName('Routine 1');
$routine1->setConfig([
'tasks' => [
[
'_class' => Set::_getClassLocator(),
'_ref' => 'task1',
'name' => 'Task 1',
'params' => [
[
'key' => 'current',
'value' => 'routine_1',
],
[
'key' => 'done',
'value' => '{{ data.current ?? "routine_1" }}',
]
],
],
],
]);
$routine1->save();
$routines['routine1'] = $routine1;
$routine2 = RoutineModel::create();
/** @var RoutineModel $routine2 */
$routine2->setName('Routine 2');
$routine2->setConfig([
'tasks' => [
[
'_class' => Set::_getClassLocator(),
'_ref' => 'task2',
'name' => 'Task 2',
'params' => [
[
'key' => 'current',
'value' => 'routine_2',
]
],
],
],
]);
$routine2->save( true );
$routines['routine2'] = $routine2;
return $routines;
}
}