Skip to content

Commit 8110598

Browse files
committed
feature symfony#23593 [Workflow] Adding workflow name to the announce event (Nyholm)
This PR was squashed before being merged into the 3.4 branch (closes symfony#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
2 parents 6bbb391 + f4c5cff commit 8110598

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.4.0
5+
-----
6+
7+
* Added support for `Event::getWorkflowName()` for "announce" events.
8+
49
3.3.0
510
-----
611

src/Symfony/Component/Workflow/Tests/WorkflowTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,35 @@ public function testApplyWithEventDispatcher()
276276
$this->assertSame($eventNameExpected, $eventDispatcher->dispatchedEvents);
277277
}
278278

279+
public function testEventName()
280+
{
281+
$definition = $this->createComplexWorkflowDefinition();
282+
$subject = new \stdClass();
283+
$subject->marking = null;
284+
$dispatcher = new EventDispatcher();
285+
$name = 'workflow_name';
286+
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, $name);
287+
288+
$assertWorkflowName = function (Event $event) use ($name) {
289+
$this->assertEquals($name, $event->getWorkflowName());
290+
};
291+
292+
$eventNames = array(
293+
'workflow.guard',
294+
'workflow.leave',
295+
'workflow.transition',
296+
'workflow.enter',
297+
'workflow.entered',
298+
'workflow.announce',
299+
);
300+
301+
foreach ($eventNames as $eventName) {
302+
$dispatcher->addListener($eventName, $assertWorkflowName);
303+
}
304+
305+
$workflow->apply($subject, 't1');
306+
}
307+
279308
public function testMarkingStateOnApplyWithEventDispatcher()
280309
{
281310
$definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f'))));

src/Symfony/Component/Workflow/Workflow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private function announce($subject, Transition $initialTransition, Marking $mark
298298
return;
299299
}
300300

301-
$event = new Event($subject, $marking, $initialTransition);
301+
$event = new Event($subject, $marking, $initialTransition, $this->name);
302302

303303
$this->dispatcher->dispatch('workflow.announce', $event);
304304
$this->dispatcher->dispatch(sprintf('workflow.%s.announce', $this->name), $event);

0 commit comments

Comments
 (0)