From 87839cfaf94e3a6b426036b7ab63b80ef89a6fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 6 Apr 2019 14:37:18 +0200 Subject: [PATCH] [Workflow] Finished integration of initial_marking + deprecated support for workflow + single state markin store --- .../DependencyInjection/Configuration.php | 15 ++-- .../FrameworkExtension.php | 14 ++-- .../Fixtures/php/workflow-legacy.php | 8 +- .../workflow_with_property_and_service.php | 32 -------- .../Fixtures/xml/workflow-legacy.xml | 5 +- .../xml/workflow_with_guard_expression.xml | 4 - ...th_multiple_transitions_with_same_name.xml | 4 - .../workflow_with_property_and_service.xml | 21 ------ .../Fixtures/xml/workflows.xml | 5 +- .../Fixtures/yml/workflow-legacy.yml | 6 +- .../workflow_with_property_and_service.yml | 17 ----- .../FrameworkExtensionTest.php | 25 +++---- .../PhpFrameworkExtensionTest.php | 73 +------------------ 13 files changed, 43 insertions(+), 186 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 8a7062c4b6..a398054c5f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -282,8 +282,15 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('argument') ->children() ->enumNode('type') - ->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.') ->values(['multiple_state', 'single_state', 'method']) + ->validate() + ->ifTrue(function ($v) { return 'method' !== $v; }) + ->then(function ($v) { + @trigger_error('Passing something else than "method" has been deprecated in Symfony 4.3.', E_USER_DEPRECATED); + + return $v; + }) + ->end() ->end() ->arrayNode('arguments') ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.') @@ -296,7 +303,7 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->scalarNode('property') - ->defaultNull() + ->defaultValue('marking') ->end() ->scalarNode('service') ->cannotBeEmpty() @@ -310,10 +317,6 @@ class Configuration implements ConfigurationInterface ->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); }) ->thenInvalid('"arguments" and "service" cannot be used together.') ->end() - ->validate() - ->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); }) - ->thenInvalid('"property" and "service" cannot be used together.') - ->end() ->end() ->arrayNode('supports') ->beforeNormalization() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index e10af2e178..a4e33ba744 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -644,14 +644,15 @@ class FrameworkExtension extends Extension // Create MarkingStore if (isset($workflow['marking_store']['type'])) { $markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']); - foreach ($workflow['marking_store']['arguments'] as $argument) { - $markingStoreDefinition->addArgument($argument); - } if ('method' === $workflow['marking_store']['type']) { $markingStoreDefinition->setArguments([ 'state_machine' === $type, //single state - $workflow['marking_store']['property'] ?? 'marking', + $workflow['marking_store']['property'], ]); + } else { + foreach ($workflow['marking_store']['arguments'] as $argument) { + $markingStoreDefinition->addArgument($argument); + } } } elseif (isset($workflow['marking_store']['service'])) { $markingStoreDefinition = new Reference($workflow['marking_store']['service']); @@ -676,10 +677,6 @@ class FrameworkExtension extends Extension case 'state_machine' === $workflow['type']: $validator = new Workflow\Validator\StateMachineValidator(); break; - case 'method' === ($workflow['marking_store']['type'] ?? null): - $singlePlace = $workflow['marking_store']['arguments'][0] ?? false; - $validator = new Workflow\Validator\WorkflowValidator($singlePlace); - break; case 'single_state' === ($workflow['marking_store']['type'] ?? null): $validator = new Workflow\Validator\WorkflowValidator(true); break; @@ -687,6 +684,7 @@ class FrameworkExtension extends Extension $validator = new Workflow\Validator\WorkflowValidator(false); break; } + if ($validator) { $realDefinition = (new Workflow\DefinitionBuilder($places)) ->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php index 729fe03f33..cad94fc773 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php @@ -3,7 +3,13 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'legacy' => [ - 'type' => 'workflow', + 'type' => 'state_machine', + 'marking_store' => [ + 'type' => 'single_state', + 'arguments' => [ + 'state', + ], + ], 'supports' => [ stdClass::class, ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php deleted file mode 100644 index 4129332d00..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php +++ /dev/null @@ -1,32 +0,0 @@ -loadFromExtension('framework', [ - 'workflows' => [ - 'my_workflow' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'property' => 'states', - 'service' => 'workflow_service', - ], - 'supports' => [ - FrameworkExtensionTest::class, - ], - 'places' => [ - 'first', - 'last', - ], - 'transitions' => [ - 'go' => [ - 'from' => [ - 'first', - ], - 'to' => [ - 'last', - ], - ], - ], - ], - ], -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml index b59bd6c29f..5a46d24d0d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml @@ -7,7 +7,10 @@ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + + + state + stdClass diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml index e310c0d11d..ffc12c4d0d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml @@ -9,10 +9,6 @@ draft - - a - a - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest draft wait_for_journalist diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml index 5cb7d75e88..db79f9323c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml @@ -9,10 +9,6 @@ draft - - a - a - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml deleted file mode 100644 index 2b2de8c368..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - - - - a - a - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml index e0340d5418..0c6a638df4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml @@ -9,10 +9,7 @@ draft - - a - a - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml index 7ff70074d4..19f51dc9f4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml @@ -1,7 +1,11 @@ framework: workflows: legacy: - type: workflow + type: state_machine + marking_store: + type: single_state + arguments: + - state initial_place: draft supports: - stdClass diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml deleted file mode 100644 index 520c689aac..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml +++ /dev/null @@ -1,17 +0,0 @@ -framework: - workflows: - my_workflow: - marking_store: - property: state - service: workflow_service - supports: - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - places: - - first - - last - transitions: - go: - from: - - first - to: - - last diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 332ac8162d..7085327e5c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -275,15 +275,18 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls())); } + /** + * @group legacy + */ public function testWorkflowLegacy() { $container = $this->createContainerFromFile('workflow-legacy'); - $this->assertTrue($container->hasDefinition('workflow.legacy'), 'Workflow is registered as a service'); - $this->assertSame('workflow.abstract', $container->getDefinition('workflow.legacy')->getParent()); - $this->assertTrue($container->hasDefinition('workflow.legacy.definition'), 'Workflow definition is registered as a service'); + $this->assertTrue($container->hasDefinition('state_machine.legacy'), 'Workflow is registered as a service'); + $this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.legacy')->getParent()); + $this->assertTrue($container->hasDefinition('state_machine.legacy.definition'), 'Workflow definition is registered as a service'); - $workflowDefinition = $container->getDefinition('workflow.legacy.definition'); + $workflowDefinition = $container->getDefinition('state_machine.legacy.definition'); $this->assertSame(['draft'], $workflowDefinition->getArgument(2)); @@ -307,17 +310,6 @@ abstract class FrameworkExtensionTest extends TestCase } /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage "property" and "service" cannot be used together. - */ - public function testWorkflowCannotHaveBothPropertyAndService() - { - $this->createContainerFromFile('workflow_with_property_and_service'); - } - - /** - * @legacy - * * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "type" and "service" cannot be used together. */ @@ -347,6 +339,7 @@ abstract class FrameworkExtensionTest extends TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "arguments" and "service" cannot be used together. + * @group legacy */ public function testWorkflowCannotHaveBothArgumentsAndService() { @@ -423,7 +416,7 @@ abstract class FrameworkExtensionTest extends TestCase ], $container->getDefinition($transitions[4])->getArguments()); } - public function testGuardExpressions() + public function testWorkflowGuardExpressions() { $container = $this->createContainerFromFile('workflow_with_guard_expression'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index 19bad8e825..259ada2f39 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -89,78 +89,8 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest } /** - * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException - * @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. + * @group legacy */ - public function testWorkflowValidationMethodSingle() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'method', - 'arguments' => [ - true, - ], - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b', 'c'], - ], - ], - ], - ], - ]); - }); - } - - public function testWorkflowValidationMethodNotSingle() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'method', - 'arguments' => [ - false, - ], - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b', 'c'], - ], - ], - ], - ], - ]); - }); - - // the test ensures that the validation does not fail (i.e. it does not throw any exceptions) - $this->addToAssertionCount(1); - } - public function testWorkflowValidationMultipleState() { $this->createContainerFromClosure(function ($container) { @@ -197,6 +127,7 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException * @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. + * @group legacy */ public function testWorkflowValidationSingleState() {