Skip to content

Commit f086ae8

Browse files
Merge branch '6.4' into 7.2
* 6.4: [GitHub] Update .github/PULL_REQUEST_TEMPLATE.md to remove SF 7.1 as it's not supported anymore [Workflow] Fix dispatch of entered event when the subject is already in this marking
2 parents f8324dc + c11061c commit f086ae8

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Tests/WorkflowTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\Workflow\Definition;
17+
use Symfony\Component\Workflow\Event\EnteredEvent;
1718
use Symfony\Component\Workflow\Event\Event;
1819
use Symfony\Component\Workflow\Event\GuardEvent;
1920
use Symfony\Component\Workflow\Event\TransitionEvent;
@@ -689,6 +690,44 @@ public function testEventDefaultInitialContext()
689690
$workflow->apply($subject, 't1');
690691
}
691692

693+
public function testEventWhenAlreadyInThisPlace()
694+
{
695+
// ┌──────┐ ┌──────────────────────┐ ┌───┐ ┌─────────────┐ ┌───┐
696+
// │ init │ ──▶ │ from_init_to_a_and_b │ ──▶ │ B │ ──▶ │ from_b_to_c │ ──▶ │ C │
697+
// └──────┘ └──────────────────────┘ └───┘ └─────────────┘ └───┘
698+
// │
699+
// │
700+
// ▼
701+
// ┌───────────────────────────────┐
702+
// │ A │
703+
// └───────────────────────────────┘
704+
$definition = new Definition(
705+
['init', 'A', 'B', 'C'],
706+
[
707+
new Transition('from_init_to_a_and_b', 'init', ['A', 'B']),
708+
new Transition('from_b_to_c', 'B', 'C'),
709+
],
710+
);
711+
712+
$subject = new Subject();
713+
$dispatcher = new EventDispatcher();
714+
$name = 'workflow_name';
715+
$workflow = new Workflow($definition, new MethodMarkingStore(), $dispatcher, $name);
716+
717+
$calls = [];
718+
$listener = function (Event $event) use (&$calls) {
719+
$calls[] = $event;
720+
};
721+
$dispatcher->addListener("workflow.$name.entered.A", $listener);
722+
723+
$workflow->apply($subject, 'from_init_to_a_and_b');
724+
$workflow->apply($subject, 'from_b_to_c');
725+
726+
$this->assertCount(1, $calls);
727+
$this->assertInstanceOf(EnteredEvent::class, $calls[0]);
728+
$this->assertSame('from_init_to_a_and_b', $calls[0]->getTransition()->getName());
729+
}
730+
692731
public function testMarkingStateOnApplyWithEventDispatcher()
693732
{
694733
$definition = new Definition(range('a', 'f'), [new Transition('t', range('a', 'c'), range('d', 'f'))]);

Workflow.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,13 @@ private function entered(object $subject, ?Transition $transition, Marking $mark
385385
$this->dispatcher->dispatch($event, WorkflowEvents::ENTERED);
386386
$this->dispatcher->dispatch($event, \sprintf('workflow.%s.entered', $this->name));
387387

388-
foreach ($marking->getPlaces() as $placeName => $nbToken) {
388+
$placeNames = [];
389+
if ($transition) {
390+
$placeNames = $transition->getTos();
391+
} elseif ($this->definition->getInitialPlaces()) {
392+
$placeNames = $this->definition->getInitialPlaces();
393+
}
394+
foreach ($placeNames as $placeName) {
389395
$this->dispatcher->dispatch($event, \sprintf('workflow.%s.entered.%s', $this->name, $placeName));
390396
}
391397
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy