Skip to content

Commit 87839cf

Browse files
committed
[Workflow] Finished integration of initial_marking + deprecated support for workflow + single state markin store
1 parent 73708a6 commit 87839cf

13 files changed

+43
-186
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,15 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
282282
->fixXmlConfig('argument')
283283
->children()
284284
->enumNode('type')
285-
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "method" instead as it will be the only option in Symfony 5.0.')
286285
->values(['multiple_state', 'single_state', 'method'])
286+
->validate()
287+
->ifTrue(function ($v) { return 'method' !== $v; })
288+
->then(function ($v) {
289+
@trigger_error('Passing something else than "method" has been deprecated in Symfony 4.3.', E_USER_DEPRECATED);
290+
291+
return $v;
292+
})
293+
->end()
287294
->end()
288295
->arrayNode('arguments')
289296
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.')
@@ -296,7 +303,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
296303
->end()
297304
->end()
298305
->scalarNode('property')
299-
->defaultNull()
306+
->defaultValue('marking')
300307
->end()
301308
->scalarNode('service')
302309
->cannotBeEmpty()
@@ -310,10 +317,6 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
310317
->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); })
311318
->thenInvalid('"arguments" and "service" cannot be used together.')
312319
->end()
313-
->validate()
314-
->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); })
315-
->thenInvalid('"property" and "service" cannot be used together.')
316-
->end()
317320
->end()
318321
->arrayNode('supports')
319322
->beforeNormalization()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,15 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
644644
// Create MarkingStore
645645
if (isset($workflow['marking_store']['type'])) {
646646
$markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']);
647-
foreach ($workflow['marking_store']['arguments'] as $argument) {
648-
$markingStoreDefinition->addArgument($argument);
649-
}
650647
if ('method' === $workflow['marking_store']['type']) {
651648
$markingStoreDefinition->setArguments([
652649
'state_machine' === $type, //single state
653-
$workflow['marking_store']['property'] ?? 'marking',
650+
$workflow['marking_store']['property'],
654651
]);
652+
} else {
653+
foreach ($workflow['marking_store']['arguments'] as $argument) {
654+
$markingStoreDefinition->addArgument($argument);
655+
}
655656
}
656657
} elseif (isset($workflow['marking_store']['service'])) {
657658
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
@@ -676,17 +677,14 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
676677
case 'state_machine' === $workflow['type']:
677678
$validator = new Workflow\Validator\StateMachineValidator();
678679
break;
679-
case 'method' === ($workflow['marking_store']['type'] ?? null):
680-
$singlePlace = $workflow['marking_store']['arguments'][0] ?? false;
681-
$validator = new Workflow\Validator\WorkflowValidator($singlePlace);
682-
break;
683680
case 'single_state' === ($workflow['marking_store']['type'] ?? null):
684681
$validator = new Workflow\Validator\WorkflowValidator(true);
685682
break;
686683
case 'multiple_state' === ($workflow['marking_store']['type'] ?? false):
687684
$validator = new Workflow\Validator\WorkflowValidator(false);
688685
break;
689686
}
687+
690688
if ($validator) {
691689
$realDefinition = (new Workflow\DefinitionBuilder($places))
692690
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
$container->loadFromExtension('framework', [
44
'workflows' => [
55
'legacy' => [
6-
'type' => 'workflow',
6+
'type' => 'state_machine',
7+
'marking_store' => [
8+
'type' => 'single_state',
9+
'arguments' => [
10+
'state',
11+
],
12+
],
713
'supports' => [
814
stdClass::class,
915
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php

-32
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config>
10-
<framework:workflow name="legacy" type="workflow" initial-place="draft">
10+
<framework:workflow name="legacy" type="state_machine" initial-place="draft">
11+
<framework:marking-store type="single_state">
12+
<framework:argument>state</framework:argument>
13+
</framework:marking-store>
1114
<framework:support>stdClass</framework:support>
1215
<framework:place name="draft" />
1316
<framework:place name="published" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
<framework:config>
1010
<framework:workflow name="article" type="workflow">
1111
<framework:initial-marking>draft</framework:initial-marking>
12-
<framework:marking-store>
13-
<framework:argument>a</framework:argument>
14-
<framework:argument>a</framework:argument>
15-
</framework:marking-store>
1612
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
1713
<framework:place>draft</framework:place>
1814
<framework:place>wait_for_journalist</framework:place>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
<framework:config>
1010
<framework:workflow name="article" type="workflow">
1111
<framework:initial-marking>draft</framework:initial-marking>
12-
<framework:marking-store type="multiple_state">
13-
<framework:argument>a</framework:argument>
14-
<framework:argument>a</framework:argument>
15-
</framework:marking-store>
1612
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
1713
<framework:place name="draft" />
1814
<framework:place name="wait_for_journalist" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml

-21
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
<framework:config>
1010
<framework:workflow name="article" type="workflow">
1111
<framework:initial-marking>draft</framework:initial-marking>
12-
<framework:marking-store type="multiple_state">
13-
<framework:argument>a</framework:argument>
14-
<framework:argument>a</framework:argument>
15-
</framework:marking-store>
12+
<framework:marking-store type="method" property="state" />
1613
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
1714
<framework:place name="draft" />
1815
<framework:place name="wait_for_journalist" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
framework:
22
workflows:
33
legacy:
4-
type: workflow
4+
type: state_machine
5+
marking_store:
6+
type: single_state
7+
arguments:
8+
- state
59
initial_place: draft
610
supports:
711
- stdClass

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml

-17
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

+9-16
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,18 @@ public function testWorkflows()
275275
$this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls()));
276276
}
277277

278+
/**
279+
* @group legacy
280+
*/
278281
public function testWorkflowLegacy()
279282
{
280283
$container = $this->createContainerFromFile('workflow-legacy');
281284

282-
$this->assertTrue($container->hasDefinition('workflow.legacy'), 'Workflow is registered as a service');
283-
$this->assertSame('workflow.abstract', $container->getDefinition('workflow.legacy')->getParent());
284-
$this->assertTrue($container->hasDefinition('workflow.legacy.definition'), 'Workflow definition is registered as a service');
285+
$this->assertTrue($container->hasDefinition('state_machine.legacy'), 'Workflow is registered as a service');
286+
$this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.legacy')->getParent());
287+
$this->assertTrue($container->hasDefinition('state_machine.legacy.definition'), 'Workflow definition is registered as a service');
285288

286-
$workflowDefinition = $container->getDefinition('workflow.legacy.definition');
289+
$workflowDefinition = $container->getDefinition('state_machine.legacy.definition');
287290

288291
$this->assertSame(['draft'], $workflowDefinition->getArgument(2));
289292

@@ -307,17 +310,6 @@ public function testWorkflowAreValidated()
307310
}
308311

309312
/**
310-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
311-
* @expectedExceptionMessage "property" and "service" cannot be used together.
312-
*/
313-
public function testWorkflowCannotHaveBothPropertyAndService()
314-
{
315-
$this->createContainerFromFile('workflow_with_property_and_service');
316-
}
317-
318-
/**
319-
* @legacy
320-
*
321313
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
322314
* @expectedExceptionMessage "type" and "service" cannot be used together.
323315
*/
@@ -347,6 +339,7 @@ public function testWorkflowShouldHaveOneOfSupportsAndSupportStrategy()
347339
/**
348340
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
349341
* @expectedExceptionMessage "arguments" and "service" cannot be used together.
342+
* @group legacy
350343
*/
351344
public function testWorkflowCannotHaveBothArgumentsAndService()
352345
{
@@ -423,7 +416,7 @@ public function testWorkflowMultipleTransitionsWithSameName()
423416
], $container->getDefinition($transitions[4])->getArguments());
424417
}
425418

426-
public function testGuardExpressions()
419+
public function testWorkflowGuardExpressions()
427420
{
428421
$container = $this->createContainerFromFile('workflow_with_guard_expression');
429422

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php

+2-71
Original file line numberDiff line numberDiff line change
@@ -89,78 +89,8 @@ public function testWorkflowValidationStateMachine()
8989
}
9090

9191
/**
92-
* @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException
93-
* @expectedExceptionMessage The marking store of workflow "article" can not store many places. But the transition "a_to_b" has too many output (2). Only one is accepted.
92+
* @group legacy
9493
*/
95-
public function testWorkflowValidationMethodSingle()
96-
{
97-
$this->createContainerFromClosure(function ($container) {
98-
$container->loadFromExtension('framework', [
99-
'workflows' => [
100-
'article' => [
101-
'type' => 'workflow',
102-
'marking_store' => [
103-
'type' => 'method',
104-
'arguments' => [
105-
true,
106-
],
107-
],
108-
'supports' => [
109-
__CLASS__,
110-
],
111-
'places' => [
112-
'a',
113-
'b',
114-
'c',
115-
],
116-
'transitions' => [
117-
'a_to_b' => [
118-
'from' => ['a'],
119-
'to' => ['b', 'c'],
120-
],
121-
],
122-
],
123-
],
124-
]);
125-
});
126-
}
127-
128-
public function testWorkflowValidationMethodNotSingle()
129-
{
130-
$this->createContainerFromClosure(function ($container) {
131-
$container->loadFromExtension('framework', [
132-
'workflows' => [
133-
'article' => [
134-
'type' => 'workflow',
135-
'marking_store' => [
136-
'type' => 'method',
137-
'arguments' => [
138-
false,
139-
],
140-
],
141-
'supports' => [
142-
__CLASS__,
143-
],
144-
'places' => [
145-
'a',
146-
'b',
147-
'c',
148-
],
149-
'transitions' => [
150-
'a_to_b' => [
151-
'from' => ['a'],
152-
'to' => ['b', 'c'],
153-
],
154-
],
155-
],
156-
],
157-
]);
158-
});
159-
160-
// the test ensures that the validation does not fail (i.e. it does not throw any exceptions)
161-
$this->addToAssertionCount(1);
162-
}
163-
16494
public function testWorkflowValidationMultipleState()
16595
{
16696
$this->createContainerFromClosure(function ($container) {
@@ -197,6 +127,7 @@ public function testWorkflowValidationMultipleState()
197127
/**
198128
* @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException
199129
* @expectedExceptionMessage The marking store of workflow "article" can not store many places. But the transition "a_to_b" has too many output (2). Only one is accepted.
130+
* @group legacy
200131
*/
201132
public function testWorkflowValidationSingleState()
202133
{

0 commit comments

Comments
 (0)