Skip to content

Commit eb5856a

Browse files
authored
Merge pull request #22 from vlsoprun/master
#21 Does not work multiple "from"
2 parents aabd265 + b982bed commit eb5856a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/WorkflowRegistry.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public function addFromArray($name, array $workflowData)
9494
$transitionName = $transition['name'];
9595
}
9696

97-
$builder->addTransition(new Transition($transitionName, $transition['from'], $transition['to']));
97+
foreach ((array)$transition['from'] as $form) {
98+
$builder->addTransition(new Transition($transitionName, $form, $transition['to']));
99+
}
98100
}
99101

100102
$definition = $builder->build();

tests/WorkflowRegistryTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,44 @@ public function testIfTransitionsWithSameNameCanBothBeUsed()
125125

126126
$this->assertTrue($workflow->can($subject, 't1'));
127127
}
128+
129+
public function testWhenMultipleFromIsUsed()
130+
{
131+
$config = [
132+
'straight' => [
133+
'type' => 'state_machine',
134+
'supports' => ['Tests\Fixtures\TestObject'],
135+
'places' => ['a', 'b', 'c'],
136+
'transitions' => [
137+
[
138+
'name' => 't1',
139+
'from' => 'a',
140+
'to' => 'b',
141+
],
142+
[
143+
'name' => 't2',
144+
'from' => [
145+
'a',
146+
'b'
147+
],
148+
'to' => 'c',
149+
],
150+
],
151+
],
152+
];
153+
154+
$registry = new WorkflowRegistry($config);
155+
$subject = new TestObject;
156+
$workflow = $registry->get($subject);
157+
158+
$markingStoreProp = new ReflectionProperty(Workflow::class, 'markingStore');
159+
$markingStoreProp->setAccessible(true);
160+
161+
$markingStore = $markingStoreProp->getValue($workflow);
162+
163+
$this->assertTrue($workflow instanceof StateMachine);
164+
$this->assertTrue($markingStore instanceof SingleStateMarkingStore);
165+
$this->assertTrue($workflow->can($subject, 't1'));
166+
$this->assertTrue($workflow->can($subject, 't2'));
167+
}
128168
}

0 commit comments

Comments
 (0)