Skip to content

Commit 3e9eeab

Browse files
bug #50362 [FrameworkBundle] Fix Workflow without a marking store definition uses marking store definition of previously defined workflow (krciga22)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Fix Workflow without a marking store definition uses marking store definition of previously defined workflow | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48099 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Fixed a bug in the `Framework Bundle` with the `registerWorkflowConfiguration()` method not initializing `$workflowMarkingStore` to null when processing each workflow. This results in subsequent workflows reusing the previously set `$workflowMarkingStore` value if one has not been explicitly configured. In the example below, `workflow_b` has no marking_store configured, so it will utilize the marking_store configuration for `workflow_a` instead of the default `MethodMarkingStore` due to this bug. ```yaml framework: workflows: workflow_a: type: 'state_machine' marking_store: type: 'method' property: 'status' workflow_b: type: 'state_machine' ``` Commits ------- 9cc5cbfd58 [FrameworkBundle] Fix Workflow without a marking store definition uses marking store definition of previously defined workflow
2 parents 7705f17 + f6ba55f commit 3e9eeab

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
920920
$workflows[$workflowId] = $definitionDefinition;
921921

922922
// Create MarkingStore
923+
$markingStoreDefinition = null;
923924
if (isset($workflow['marking_store']['type'])) {
924925
$markingStoreDefinition = new ChildDefinition('workflow.marking_store.method');
925926
$markingStoreDefinition->setArguments([
@@ -933,7 +934,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
933934
// Create Workflow
934935
$workflowDefinition = new ChildDefinition(sprintf('%s.abstract', $type));
935936
$workflowDefinition->replaceArgument(0, new Reference(sprintf('%s.definition', $workflowId)));
936-
$workflowDefinition->replaceArgument(1, $markingStoreDefinition ?? null);
937+
$workflowDefinition->replaceArgument(1, $markingStoreDefinition);
937938
$workflowDefinition->replaceArgument(3, $name);
938939
$workflowDefinition->replaceArgument(4, $workflow['events_to_dispatch']);
939940
$workflowDefinition->addTag('container.private', [

Tests/DependencyInjection/PhpFrameworkExtensionTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,62 @@ public function testWorkflowValidationStateMachine()
8585
});
8686
}
8787

88+
public function testWorkflowDefaultMarkingStoreDefinition()
89+
{
90+
$container = $this->createContainerFromClosure(function ($container) {
91+
$container->loadFromExtension('framework', [
92+
'workflows' => [
93+
'workflow_a' => [
94+
'type' => 'state_machine',
95+
'marking_store' => [
96+
'type' => 'method',
97+
'property' => 'status',
98+
],
99+
'supports' => [
100+
__CLASS__,
101+
],
102+
'places' => [
103+
'a',
104+
'b',
105+
],
106+
'transitions' => [
107+
'a_to_b' => [
108+
'from' => ['a'],
109+
'to' => ['b'],
110+
],
111+
],
112+
],
113+
'workflow_b' => [
114+
'type' => 'state_machine',
115+
'supports' => [
116+
__CLASS__,
117+
],
118+
'places' => [
119+
'a',
120+
'b',
121+
],
122+
'transitions' => [
123+
'a_to_b' => [
124+
'from' => ['a'],
125+
'to' => ['b'],
126+
],
127+
],
128+
],
129+
],
130+
]);
131+
});
132+
133+
$workflowA = $container->getDefinition('state_machine.workflow_a');
134+
$argumentsA = $workflowA->getArguments();
135+
$this->assertArrayHasKey('index_1', $argumentsA, 'workflow_a has a marking_store argument');
136+
$this->assertNotNull($argumentsA['index_1'], 'workflow_a marking_store argument is not null');
137+
138+
$workflowB = $container->getDefinition('state_machine.workflow_b');
139+
$argumentsB = $workflowB->getArguments();
140+
$this->assertArrayHasKey('index_1', $argumentsB, 'workflow_b has a marking_store argument');
141+
$this->assertNull($argumentsB['index_1'], 'workflow_b marking_store argument is null');
142+
}
143+
88144
public function testRateLimiterWithLockFactory()
89145
{
90146
try {

0 commit comments

Comments
 (0)