|
5 | 5 | use PHPUnit\Framework\TestCase;
|
6 | 6 | use Symfony\Component\EventDispatcher\EventDispatcher;
|
7 | 7 | use Symfony\Component\Workflow\Definition;
|
| 8 | +use Symfony\Component\Workflow\Event\Event; |
8 | 9 | use Symfony\Component\Workflow\Event\GuardEvent;
|
9 | 10 | use Symfony\Component\Workflow\Marking;
|
10 | 11 | use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
|
@@ -252,6 +253,41 @@ public function testApplyWithEventDispatcher()
|
252 | 253 | $this->assertSame($eventNameExpected, $eventDispatcher->dispatchedEvents);
|
253 | 254 | }
|
254 | 255 |
|
| 256 | + public function testMarkingStateOnApplyWithEventDispatcher() |
| 257 | + { |
| 258 | + $definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f')))); |
| 259 | + |
| 260 | + $subject = new \stdClass(); |
| 261 | + $subject->marking = array('a' => 1, 'b' => 1, 'c' => 1); |
| 262 | + |
| 263 | + $dispatcher = new EventDispatcher(); |
| 264 | + |
| 265 | + $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, 'test'); |
| 266 | + |
| 267 | + $assertInitialState = function (Event $event) { |
| 268 | + $this->assertEquals(new Marking(array('a' => 1, 'b' => 1, 'c' => 1)), $event->getMarking()); |
| 269 | + }; |
| 270 | + $assertTransitionState = function (Event $event) { |
| 271 | + $this->assertEquals(new Marking(array()), $event->getMarking()); |
| 272 | + }; |
| 273 | + |
| 274 | + $dispatcher->addListener('workflow.leave', $assertInitialState); |
| 275 | + $dispatcher->addListener('workflow.test.leave', $assertInitialState); |
| 276 | + $dispatcher->addListener('workflow.test.leave.a', $assertInitialState); |
| 277 | + $dispatcher->addListener('workflow.test.leave.b', $assertInitialState); |
| 278 | + $dispatcher->addListener('workflow.test.leave.c', $assertInitialState); |
| 279 | + $dispatcher->addListener('workflow.transition', $assertTransitionState); |
| 280 | + $dispatcher->addListener('workflow.test.transition', $assertTransitionState); |
| 281 | + $dispatcher->addListener('workflow.test.transition.t', $assertTransitionState); |
| 282 | + $dispatcher->addListener('workflow.enter', $assertTransitionState); |
| 283 | + $dispatcher->addListener('workflow.test.enter', $assertTransitionState); |
| 284 | + $dispatcher->addListener('workflow.test.enter.d', $assertTransitionState); |
| 285 | + $dispatcher->addListener('workflow.test.enter.e', $assertTransitionState); |
| 286 | + $dispatcher->addListener('workflow.test.enter.f', $assertTransitionState); |
| 287 | + |
| 288 | + $workflow->apply($subject, 't'); |
| 289 | + } |
| 290 | + |
255 | 291 | public function testGetEnabledTransitions()
|
256 | 292 | {
|
257 | 293 | $definition = $this->createComplexWorkflowDefinition();
|
|
0 commit comments