8000 [Workflow] Make sure we do not run the next transition on an updated … · symfony/symfony@d9dda76 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9dda76

Browse files
Nyholmfabpot
authored andcommitted
[Workflow] Make sure we do not run the next transition on an updated state
1 parent 30de3b8 commit d9dda76

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Component/Workflow/Tests/WorkflowTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ public function testApplyWithSameNameTransition2()
345345
$this->assertTrue($marking->has('d'));
346346
}
347347

348+
public function testApplyWithSameNameTransition3()
349+
{
350+
$subject = new \stdClass();
351+
$subject->marking = array('a' => 1);
352+
353+
$places = range('a', 'd');
354+
$transitions = array();
355+
$transitions[] = new Transition('t', 'a', 'b');
356+
$transitions[] = new Transition('t', 'b', 'c');
357+
$transitions[] = new Transition('t', 'c', 'd');
358+
$definition = new Definition($places, $transitions);
359+
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
360+
361+
$marking = $workflow->apply($subject, 't');
362+
// We want to make sure we do not end up in "d"
363+
$this->assertTrue($marking->has('b'));
364+
$this->assertFalse($marking->has('d'));
365+
}
366+
348367
public function testApplyWithEventDispatcher()
349368
{
350369
$definition = $this->createComplexWorkflowDefinition();

src/Symfony/Component/Workflow/Workflow.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function apply($subject, $transitionName)
139139

140140
$transitionBlockerList = null;
141141
$applied = false;
142+
$approvedTransitionQueue = array();
142143

143144
foreach ($this->definition->getTransitions() as $transition) {
144145
if ($transition->getName() !== $transitionName) {
@@ -149,7 +150,10 @@ public function apply($subject, $transitionName)
149150
if (!$transitionBlockerList->isEmpty()) {
150151
continue;
151152
}
153+
$approvedTransitionQueue[] = $transition;
154+
}
152155

156+
foreach ($approvedTransitionQueue as $transition) {
153157
$applied = true;
154158

155159
$this->leave($subject, $transition, $marking);

0 commit comments

Comments
 (0)
0