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:
commit
8110598f15
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* Added support for `Event::getWorkflowName()` for "announce" events.
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
|
@ -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'))));
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user