From e977921c957f7e8820c6fabff48311b12b440d8d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 19 Jul 2017 16:45:25 +0200 Subject: [PATCH 1/2] Adding workflow name to the announce event --- src/Symfony/Component/Workflow/CHANGELOG.md | 5 ++++ .../Component/Workflow/Tests/WorkflowTest.php | 29 +++++++++++++++++++ src/Symfony/Component/Workflow/Workflow.php | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 51a52777dfa8e..d1b50cb4ef497 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +3.4.0 +----- + + * Added support for `Event::getWorkflowName()` for "announce" events. + 3.3.0 ----- diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index 212bd5f3f9411..1127197614c40 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -276,6 +276,35 @@ public function testApplyWithEventDispatcher() $this->assertSame($eventNameExpected, $eventDispatcher->dispatchedEvents); } + public function testEventName() + { + $definition = $this->createComplexWorkflowDefinition(); + $subject = new \stdClass(); + $subject->marking = null; + $eventDispatcher = new EventDispatcherMock(); + $name = 'workflow_name'; + $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, $name); + + $assertWorkflowName = function (Event $event) use ($name) { + $this->assertEquals($name, $event->getWorkflowName()); + }; + + $eventNames = array( + 'workflow.guard', + 'workflow.leave', + 'workflow.transition', + 'workflow.enter', + 'workflow.entered', + 'workflow.announce', + ); + + foreach ($eventNames as $eventName) { + $eventDispatcher->addListener($eventName, $assertWorkflowName); + } + + $marking = $workflow->apply($subject, 't1'); + } + public function testMarkingStateOnApplyWithEventDispatcher() { $definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f')))); diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 1791b568d79be..617c05b381e09 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -298,7 +298,7 @@ private function announce($subject, Transition $initialTransition, Marking $mark return; } - $event = new Event($subject, $marking, $initialTransition); + $event = new Event($subject, $marking, $initialTransition, $this->name); $this->dispatcher->dispatch('workflow.announce', $event); $this->dispatcher->dispatch(sprintf('workflow.%s.announce', $this->name), $event); From d0636ac8fe325d28402b579657ff2c83b135cd82 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 27 Jul 2017 02:33:58 +0200 Subject: [PATCH 2/2] Updated tests --- src/Symfony/Component/Workflow/Tests/WorkflowTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index 1127197614c40..3ca61914aad1c 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -281,9 +281,9 @@ public function testEventName() $definition = $this->createComplexWorkflowDefinition(); $subject = new \stdClass(); $subject->marking = null; - $eventDispatcher = new EventDispatcherMock(); + $dispatcher = new EventDispatcher(); $name = 'workflow_name'; - $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, $name); + $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, $name); $assertWorkflowName = function (Event $event) use ($name) { $this->assertEquals($name, $event->getWorkflowName()); @@ -299,10 +299,10 @@ public function testEventName() ); foreach ($eventNames as $eventName) { - $eventDispatcher->addListener($eventName, $assertWorkflowName); + $dispatcher->addListener($eventName, $assertWorkflowName); } - $marking = $workflow->apply($subject, 't1'); + $workflow->apply($subject, 't1'); } public function testMarkingStateOnApplyWithEventDispatcher()