diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index ed97fb518df95..f33085f8724a8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -255,6 +255,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) ->ifString() ->then(function ($v) { return array($v); }) ->end() + ->requiresAtLeastOneElement() ->prototype('scalar') ->end() ->end() @@ -263,13 +264,12 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) ->end() ->end() ->validate() - ->always(function ($v) { - if (isset($v['type']) && isset($v['service'])) { - throw new \InvalidArgumentException('"type" and "service" could not be used together.'); - } - - return $v; - }) + ->ifTrue(function ($v) { return isset($v['type']) && isset($v['service']); }) + ->thenInvalid('"type" and "service" cannot be used together.') + ->end() + ->validate() + ->ifTrue(function ($v) { return isset($v['arguments']) && isset($v['service']); }) + ->thenInvalid('"arguments" and "service" cannot be used together.') ->end() ->end() ->arrayNode('supports') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_arguments_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_arguments_and_service.php new file mode 100644 index 0000000000000..d97f9700a0f1b --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_arguments_and_service.php @@ -0,0 +1,31 @@ +loadFromExtension('framework', array( + 'workflows' => array( + 'my_workflow' => array( + 'marking_store' => array( + 'arguments' => array('a', 'b'), + 'service' => 'workflow_service', + ), + 'supports' => array( + FrameworkExtensionTest::class, + ), + 'places' => array( + 'first', + 'last', + ), + 'transitions' => array( + 'go' => array( + 'from' => array( + 'first', + ), + 'to' => array( + 'last', + ), + ), + ), + ), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_type_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_type_and_service.php new file mode 100644 index 0000000000000..7d9e596408c97 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_type_and_service.php @@ -0,0 +1,31 @@ +loadFromExtension('framework', array( + 'workflows' => array( + 'my_workflow' => array( + 'marking_store' => array( + 'type' => 'multiple_state', + 'service' => 'workflow_service', + ), + 'supports' => array( + FrameworkExtensionTest::class, + ), + 'places' => array( + 'first', + 'last', + ), + 'transitions' => array( + 'go' => array( + 'from' => array( + 'first', + ), + 'to' => array( + 'last', + ), + ), + ), + ), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_arguments_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_arguments_and_service.xml new file mode 100644 index 0000000000000..02502296f77de --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_arguments_and_service.xml @@ -0,0 +1,24 @@ + + + + + + + + a + a + + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + first + last + + a + a + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_type_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_type_and_service.xml new file mode 100644 index 0000000000000..7ec450f6537ee --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_type_and_service.xml @@ -0,0 +1,21 @@ + + + + + + + + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + first + last + + a + a + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_arguments_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_arguments_and_service.yml new file mode 100644 index 0000000000000..a46d4b67e6b24 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_arguments_and_service.yml @@ -0,0 +1,19 @@ +framework: + workflows: + my_workflow: + marking_store: + arguments: + - a + - b + 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/Fixtures/yml/workflow_with_type_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_type_and_service.yml new file mode 100644 index 0000000000000..000ba10dfb8d2 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_type_and_service.yml @@ -0,0 +1,17 @@ +framework: + workflows: + my_workflow: + marking_store: + type: multiple_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 2a0aa0196fc84..c1ee84685654f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -167,6 +167,24 @@ public function testWorkflows() $this->assertSame('start', $stateMachineDefinition->getArgument(2)); } + /** + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage "type" and "service" cannot be used together. + */ + public function testWorkflowCannotHaveBothTypeAndService() + { + $this->createContainerFromFile('workflow_with_type_and_service'); + } + + /** + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage "arguments" and "service" cannot be used together. + */ + public function testWorkflowCannotHaveBothArgumentsAndService() + { + $this->createContainerFromFile('workflow_with_arguments_and_service'); + } + public function testRouter() { $container = $this->createContainerFromFile('full');