|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\EventDispatcher\EventDispatcher;
|
16 | 16 | use Symfony\Component\Workflow\Definition;
|
| 17 | +use Symfony\Component\Workflow\Event\EnteredEvent; |
17 | 18 | use Symfony\Component\Workflow\Event\Event;
|
18 | 19 | use Symfony\Component\Workflow\Event\GuardEvent;
|
19 | 20 | use Symfony\Component\Workflow\Event\TransitionEvent;
|
@@ -689,6 +690,44 @@ public function testEventDefaultInitialContext()
|
689 | 690 | $workflow->apply($subject, 't1');
|
690 | 691 | }
|
691 | 692 |
|
| 693 | + public function testEventWhenAlreadyInThisPlace() |
| 694 | + { |
| 695 | + // ┌──────┐ ┌──────────────────────┐ ┌───┐ ┌─────────────┐ ┌───┐ |
| 696 | + // │ init │ ──▶ │ from_init_to_a_and_b │ ──▶ │ B │ ──▶ │ from_b_to_c │ ──▶ │ C │ |
| 697 | + // └──────┘ └──────────────────────┘ └───┘ └─────────────┘ └───┘ |
| 698 | + // │ |
| 699 | + // │ |
| 700 | + // ▼ |
| 701 | + // ┌───────────────────────────────┐ |
| 702 | + // │ A │ |
| 703 | + // └───────────────────────────────┘ |
| 704 | + $definition = new Definition( |
| 705 | + ['init', 'A', 'B', 'C'], |
| 706 | + [ |
| 707 | + new Transition('from_init_to_a_and_b', 'init', ['A', 'B']), |
| 708 | + new Transition('from_b_to_c', 'B', 'C'), |
| 709 | + ], |
| 710 | + ); |
| 711 | + |
| 712 | + $subject = new Subject(); |
| 713 | + $dispatcher = new EventDispatcher(); |
| 714 | + $name = 'workflow_name'; |
| 715 | + $workflow = new Workflow($definition, new MethodMarkingStore(), $dispatcher, $name); |
| 716 | + |
| 717 | + $calls = []; |
| 718 | + $listener = function (Event $event) use (&$calls) { |
| 719 | + $calls[] = $event; |
| 720 | + }; |
| 721 | + $dispatcher->addListener("workflow.$name.entered.A", $listener); |
| 722 | + |
| 723 | + $workflow->apply($subject, 'from_init_to_a_and_b'); |
| 724 | + $workflow->apply($subject, 'from_b_to_c'); |
| 725 | + |
| 726 | + $this->assertCount(1, $calls); |
| 727 | + $this->assertInstanceOf(EnteredEvent::class, $calls[0]); |
| 728 | + $this->assertSame('from_init_to_a_and_b', $calls[0]->getTransition()->getName()); |
| 729 | + } |
| 730 | + |
692 | 731 | public function testMarkingStateOnApplyWithEventDispatcher()
|
693 | 732 | {
|
694 | 733 | $definition = new Definition(range('a', 'f'), [new Transition('t', range('a', 'c'), range('d', 'f'))]);
|
|
0 commit comments