feature #23593 [Workflow] Adding workflow name to the announce event (Nyholm)

This PR was squashed before being merged into the 3.4 branch (closes #23593).

Discussion
----------

[Workflow] Adding workflow name to the announce event

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Im not sure why this as not been added before. When dispatching all other events we use the forth parameter to Event.

Ping @lyrixx

Commits
-------

f4c5cff [Workflow] Adding workflow name to the announce event
This commit is contained in:
Grégoire Pineau 2017-07-27 10:17:50 +02:00
commit 8110598f15
3 changed files with 35 additions and 1 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
3.4.0
-----
* Added support for `Event::getWorkflowName()` for "announce" events.
3.3.0
-----

View File

@ -276,6 +276,35 @@ class WorkflowTest extends TestCase
$this->assertSame($eventNameExpected, $eventDispatcher->dispatchedEvents);
}
public function testEventName()
{
$definition = $this->createComplexWorkflowDefinition();
$subject = new \stdClass();
$subject->marking = null;
$dispatcher = new EventDispatcher();
$name = 'workflow_name';
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, $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) {
$dispatcher->addListener($eventName, $assertWorkflowName);
}
$workflow->apply($subject, 't1');
}
public function testMarkingStateOnApplyWithEventDispatcher()
{
$definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f'))));

View File

@ -298,7 +298,7 @@ class Workflow
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);