[Workflow] Adding workflow name to the announce event

This commit is contained in:
Tobias Nyholm 2017-07-19 16:45:25 +02:00 committed by Grégoire Pineau
parent 6bbb391175
commit f4c5cff97d
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);