|
5 | 5 | use PHPUnit\Framework\TestCase;
|
6 | 6 | use Symfony\Component\EventDispatcher\EventDispatcher;
|
7 | 7 | use Symfony\Component\Workflow\Event\GuardEvent;
|
| 8 | +use Symfony\Component\Workflow\Exception\NotEnabledTransitionException; |
8 | 9 | use Symfony\Component\Workflow\StateMachine;
|
9 | 10 | use Symfony\Component\Workflow\TransitionBlocker;
|
10 | 11 |
|
@@ -84,27 +85,52 @@ public function testBuildTransitionBlockerListReturnsExpectedReasonOnBranchMerge
|
84 | 85 | $subject = new Subject();
|
85 | 86 |
|
86 | 87 | // There may be multiple transitions with the same name. Make sure that transitions
|
87 |
| - // that are not enabled by the marking are evaluated. |
| 88 | + // that are enabled by the marking are evaluated. |
88 | 89 | // see https://github.com/symfony/symfony/issues/28432
|
89 | 90 |
|
90 |
| - // Test if when you are in place "a"trying transition "t1" then returned |
| 91 | + // Test if when you are in place "a" and trying to apply "t1" then it returns |
91 | 92 | // blocker list contains guard blocker instead blockedByMarking
|
92 | 93 | $subject->setMarking('a');
|
93 | 94 | $transitionBlockerList = $net->buildTransitionBlockerList($subject, 't1');
|
94 | 95 | $this->assertCount(1, $transitionBlockerList);
|
95 | 96 | $blockers = iterator_to_array($transitionBlockerList);
|
96 |
| - |
97 | 97 | $this->assertSame('Transition blocker of place a', $blockers[0]->getMessage());
|
98 | 98 | $this->assertSame('blocker', $blockers[0]->getCode());
|
99 | 99 |
|
100 |
| - // Test if when you are in place "d" trying transition "t1" then |
101 |
| - // returned blocker list contains guard blocker instead blockedByMarking |
| 100 | + // Test if when you are in place "d" and trying to apply "t1" then |
| 101 | + // it returns blocker list contains guard blocker instead blockedByMarking |
102 | 102 | $subject->setMarking('d');
|
103 | 103 | $transitionBlockerList = $net->buildTransitionBlockerList($subject, 't1');
|
104 | 104 | $this->assertCount(1, $transitionBlockerList);
|
105 | 105 | $blockers = iterator_to_array($transitionBlockerList);
|
106 |
| - |
107 | 106 | $this->assertSame('Transition blocker of place d', $blockers[0]->getMessage());
|
108 | 107 | $this->assertSame('blocker', $blockers[0]->getCode());
|
109 | 108 | }
|
| 109 | + |
| 110 | + public function testApplyReturnsExpectedReasonOnBranchMerge() |
| 111 | + { |
| 112 | + $definition = $this->createComplexStateMachineDefinition(); |
| 113 | + |
| 114 | + $dispatcher = new EventDispatcher(); |
| 115 | + $net = new StateMachine($definition, null, $dispatcher); |
| 116 | + |
| 117 | + $dispatcher->addListener('workflow.guard', function (GuardEvent $event) { |
| 118 | + $event->addTransitionBlocker(new TransitionBlocker(sprintf('Transition blocker of place %s', $event->getTransition()->getFroms()[0]), 'blocker')); |
| 119 | + }); |
| 120 | + |
| 121 | + $subject = new Subject(); |
| 122 | + |
| 123 | + // There may be multiple transitions with the same name. Make sure that all transitions |
| 124 | + // that are enabled by the marking are evaluated. |
| 125 | + // see https://github.com/symfony/symfony/issues/34489 |
| 126 | + |
| 127 | + try { |
| 128 | + $net->apply($subject, 't1'); |
| 129 | + $this->fail(); |
| 130 | + } catch (NotEnabledTransitionException $e) { |
| 131 | + $blockers = iterator_to_array($e->getTransitionBlockerList()); |
| 132 | + $this->assertSame('Transition blocker of place a', $blockers[0]->getMessage()); |
| 133 | + $this->assertSame('blocker', $blockers[0]->getCode()); |
| 134 | + } |
| 135 | + } |
110 | 136 | }
|
0 commit comments