Skip to content

Commit 329fdb0

Browse files
committed
[Workflow] improve workflow config validation
1 parent e493a1b commit 329fdb0

8 files changed

+180
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
250250
->ifString()
251251
->then(function ($v) { return array($v); })
252252
->end()
253+
->requiresAtLeastOneElement()
253254
->prototype('scalar')
254255
->end()
255256
->end()
@@ -258,13 +259,12 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
258259
->end()
259260
->end()
260261
->validate()
261-
->always(function ($v) {
262-
if (isset($v['type']) && isset($v['service'])) {
263-
throw new \InvalidArgumentException('"type" and "service" could not be used together.');
264-
}
265-
266-
return $v;
267-
})
262+
->ifTrue(function ($v) { return isset($v['type']) && isset($v['service']); })
263+
->thenInvalid('"type" and "service" cannot be used together.')
264+
->end()
265+
->validate()
266+
->ifTrue(function ($v) { return isset($v['arguments']) && isset($v['service']); })
267+
->thenInvalid('"arguments" and "service" cannot be used together.')
268268
->end()
269269
->end()
270270
->arrayNode('supports')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'my_workflow' => array(
8+
'marking_store' => array(
9+
'arguments' => array('a', 'b'),
10+
'service' => 'workflow_service',
11+
),
12+
'supports' => array(
13+
FrameworkExtensionTest::class,
14+
),
15+
'places' => array(
16+
'first',
17+
'last',
18+
),
19+
'transitions' => array(
20+
'go' => array(
21+
'from' => array(
22+
'first',
23+
),
24+
'to' => array(
25+
'last',
26+
),
27+
),
28+
),
29+
),
30+
),
31+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'my_workflow' => array(
8+
'marking_store' => array(
9+
'type' => 'multiple_state',
10+
'service' => 'workflow_service',
11+
),
12+
'supports' => array(
13+
FrameworkExtensionTest::class,
14+
),
15+
'places' => array(
16+
'first',
17+
'last',
18+
),
19+
'transitions' => array(
20+
'go' => array(
21+
'from' => array(
22+
'first',
23+
),
24+
'to' => array(
25+
'last',
26+
),
27+
),
28+
),
29+
),
30+
),
31+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflows>
11+
<framework:workflow name="my_workflow">
12+
<framework:marking-store>
13+
<framework:arguments>a</framework:arguments>
14+
<framework:arguments>a</framework:arguments>
15+
<framework:service>workflow_service</framework:service>
16+
</framework:marking-store>
17+
<framework:supports>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:supports>
18+
<framework:places>first</framework:places>
19+
<framework:places>last</framework:places>
20+
<framework:transitions>
21+
<framework:transition name="foobar">
22+
<framework:from>a</framework:from>
23+
<framework:to>a</framework:to>
24+
</framework:transition>
25+
</framework:transitions>
26+
</framework:workflow>
27+
</framework:workflows>
28+
</framework:config>
29+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflows>
11+
<framework:workflow name="my_workflow">
12+
<framework:marking-store>
13+
<framework:type>multiple_state</framework:type>
14+
<framework:service>workflow_service</framework:service>
15+
</framework:marking-store>
16+
<framework:supports>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:supports>
17+
<framework:places>first</framework:places>
18+
<framework:places>last</framework:places>
19+
<framework:transitions>
20+
<framework:transition name="foobar">
21+
<framework:from>a</framework:from>
22+
<framework:to>a</framework:to>
23+
</framework:transition>
24+
</framework:transitions>
25+
</framework:workflow>
26+
</framework:workflows>
27+
</framework:config>
28+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
framework:
2+
workflows:
3+
my_workflow:
4+
marking_store:
5+
arguments:
6+
- a
7+
- b
8+
service: workflow_service
9+
supports:
10+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
11+
places:
12+
- first
13+
- last
14+
transitions:
15+
go:
16+
from:
17+
- first
18+
to:
19+
- last
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
framework:
2+
workflows:
3+
my_workflow:
4+
marking_store:
5+
type: multiple_state
6+
service: workflow_service
7+
supports:
8+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9+
places:
10+
- first
11+
- last
12+
transitions:
13+
go:
14+
from:
15+
- first
16+
to:
17+
- last

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ public function testWorkflow()
127127
$this->assertTrue($container->hasDefinition('workflow.my_workflow'));
128128
}
129129

130+
/**
131+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
132+
* @expectedExceptionMessage "type" and "service" cannot be used together.
133+
*/
134+
public function testWorkflowCannotHaveBothTypeAndService()
135+
{
136+
$this->createContainerFromFile('workflow_with_type_and_service');
137+
}
138+
139+
/**
140+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
141+
* @expectedExceptionMessage "arguments" and "service" cannot be used together.
142+
*/
143+
public function testWorkflowCannotHaveBothArgumentsAndService()
144+
{
145+
$this->createContainerFromFile('workflow_with_arguments_and_service');
146+
}
147+
130148
public function testRouter()
131149
{
132150
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)