Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d377344

Browse filesBrowse files
committed
[Workflow] Fixed code and tests
1 parent 1843012 commit d377344
Copy full SHA for d377344
Expand file treeCollapse file tree

14 files changed

+182
-18
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
295295
->scalarNode('support_strategy')
296296
->cannotBeEmpty()
297297
->end()
298-
->scalarNode('initial_place')->defaultNull()->end()
298+
->scalarNode('initial_place')
299+
->defaultNull()
300+
->end()
299301
->arrayNode('places')
300302
->isRequired()
301303
->requiresAtLeastOneElement()
@@ -356,9 +358,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
356358
->end()
357359
->end()
358360
->validate()
359-
->ifTrue(function ($v) { return isset($v['supports']) && isset($v['support_strategy']); })
361+
->ifTrue(function ($v) {
362+
return $v['supports'] && isset($v['support_strategy']);
363+
})
360364
->thenInvalid('"supports" and "support_strategy" cannot be used together.')
361365
->end()
366+
->validate()
367+
->ifTrue(function ($v) {
368+
return !$v['supports'] && !isset($v['support_strategy']);
369+
})
370+
->thenInvalid('"supports" or "support_strategy" should be configured.')
371+
->end()
362372
->end()
363373
->end()
364374
->end()

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
476476
$container->setDefinition(sprintf('%s.definition', $workflowId), $definitionDefinition);
477477

478478
// Add workflow to Registry
479-
if (isset($workflow['supports'])) {
479+
if ($workflow['supports']) {
480480
foreach ($workflow['supports'] as $supportedClassName) {
481481
$strategyDefinition = new Definition(ClassInstanceSupportStrategy::class, array($supportedClassName));
482482
$strategyDefinition->setPublic(false);

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@
232232
<xsd:complexType name="workflow">
233233
<xsd:sequence>
234234
<xsd:element name="marking-store" type="marking_store" />
235-
<xsd:element name="support" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
235+
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
236+
<xsd:element name="support-strategy" type="xsd:string" minOccurs="0" maxOccurs="1" />
236237
<xsd:element name="place" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
237238
<xsd:element name="transition" type="transition" minOccurs="1" maxOccurs="unbounded" />
238239
</xsd:sequence>
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+
),
11+
'supports' => array(
12+
FrameworkExtensionTest::class,
13+
),
14+
'support_strategy' => 'foobar',
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,27 @@
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+
),
11+
'places' => array(
12+
'first',
13+
'last',
14+
),
15+
'transitions' => array(
16+
'go' => array(
17+
'from' => array(
18+
'first',
19+
),
20+
'to' => array(
21+
'last',
22+
),
23+
),
24+
),
25+
),
26+
),
27+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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:workflow name="my_workflow">
11+
<framework:marking-store type="multiple_state"/>
12+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
13+
<framework:support-strategy>foobar</framework:support-strategy>
14+
<framework:place>first</framework:place>
15+
<framework:place>last</framework:place>
16+
<framework:transition name="foobar">
17+
<framework:from>a</framework:from>
18+
<framework:to>a</framework:to>
19+
</framework:transition>
20+
</framework:workflow>
21+
</framework:config>
22+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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:workflow name="my_workflow">
11+
<framework:marking-store type="multiple_state"/>
12+
<framework:place>first</framework:place>
13+
<framework:place>last</framework:place>
14+
<framework:transition name="foobar">
15+
<framework:from>a</framework:from>
16+
<framework:to>a</framework:to>
17+
</framework:transition>
18+
</framework:workflow>
19+
</framework:config>
20+
</container>
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+
supports:
7+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
8+
support_strategy: foobar
9+
places:
10+
- first
11+
- last
12+
transitions:
13+
go:
14+
from:
15+
- first
16+
to:
17+
- last
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
framework:
2+
workflows:
3+
my_workflow:
4+
marking_store:
5+
type: multiple_state
6+
places:
7+
- first
8+
- last
9+
transitions:
10+
go:
11+
from:
12+
- first
13+
to:
14+
- last

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ public function testWorkflows()
168168
$this->assertCount(9, $stateMachineDefinition->getArgument(1));
169169
$this->assertSame('start', $stateMachineDefinition->getArgument(2));
170170

171-
172171
$serviceMarkingStoreWorkflowDefinition = $container->getDefinition('workflow.service_marking_store_workflow');
173172
/** @var Reference $markingStoreRef */
174173
$markingStoreRef = $serviceMarkingStoreWorkflowDefinition->getArgument(1);
@@ -189,6 +188,24 @@ public function testWorkflowCannotHaveBothTypeAndService()
189188
$this->createContainerFromFile('workflow_with_type_and_service');
190189
}
191190

191+
/**
192+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
193+
* @expectedExceptionMessage "supports" and "support_strategy" cannot be used together.
194+
*/
195+
public function testWorkflowCannotHaveBothSupportsAndSupportStrategy()
196+
{
197+
$this->createContainerFromFile('workflow_with_support_and_support_strategy');
198+
}
199+
200+
/**
201+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
202+
* @expectedExceptionMessage "supports" or "support_strategy" should be configured.
203+
*/
204+
public function testWorkflowShouldHaveOneOfSupportsAndSupportStrategy()
205+
{
206+
$this->createContainerFromFile('workflow_without_support_and_support_strategy');
207+
}
208+
192209
/**
193210
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
194211
* @expectedExceptionMessage "arguments" and "service" cannot be used together.

‎src/Symfony/Component/Workflow/Registry.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Registry.php
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Workflow;
1313

1414
use Symfony\Component\Workflow\Exception\InvalidArgumentException;
15+
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
1516
use Symfony\Component\Workflow\SupportStrategy\SupportStrategyInterface;
1617

1718
/**
@@ -30,6 +31,8 @@ public function add(Workflow $workflow, $supportStrategy)
3031
{
3132
if (!$supportStrategy instanceof SupportStrategyInterface) {
3233
@trigger_error('Support of class name string was deprecated after version 3.2 and won\'t work anymore in 4.0.', E_USER_DEPRECATED);
34+
35+
$supportStrategy = new ClassInstanceSupportStrategy($supportStrategy);
3336
}
3437

3538
$this->workflows[] = array($workflow, $supportStrategy);
@@ -63,17 +66,10 @@ public function get($subject, $workflowName = null)
6366

6467
private function supports(Workflow $workflow, $supportStrategy, $subject, $workflowName)
6568
{
66-
if (is_string($supportStrategy) && !$subject instanceof $supportStrategy) {
67-
return false;
68-
}
69-
if ($supportStrategy instanceof SupportStrategyInterface && !$supportStrategy->supports($workflow, $subject)) {
69+
if (null !== $workflowName && $workflowName !== $workflow->getName()) {
7070
return false;
7171
}
7272

73-
if (null === $workflowName) {
74-
return true;
75-
}
76-
77-
return $workflowName === $workflow->getName();
73+
return $supportStrategy->supports($workflow, $subject);
7874
}
7975
}

‎src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
use Symfony\Component\Workflow\Workflow;
66

7-
class ClassInstanceSupportStrategy implements SupportStrategyInterface
7+
/**
8+
* @author Andreas Kleemann <akleemann@inviqa.com>
9+
*/
10+
final class ClassInstanceSupportStrategy implements SupportStrategyInterface
811
{
912
private $className;
1013

14+
/**
15+
* @param string $className a FQCN
16+
*/
1117
public function __construct($className)
1218
{
1319
$this->className = $className;

‎src/Symfony/Component/Workflow/SupportStrategy/SupportStrategyInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/SupportStrategy/SupportStrategyInterface.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\Workflow\Workflow;
1515

16+
/**
17+
* @author Andreas Kleemann <akleemann@inviqa.com>
18+
*/
1619
interface SupportStrategyInterface
1720
{
1821
/**

‎src/Symfony/Component/Workflow/Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ public function testSupportsIfClassInstance()
1111
{
1212
$strategy = new ClassInstanceSupportStrategy('Symfony\Component\Workflow\Tests\SupportStrategy\Subject1');
1313

14-
$this->assertTrue($strategy->supports($this->getWorkflow(), new Subject1()));
14+
$this->assertTrue($strategy->supports($this->createWorkflow(), new Subject1()));
1515
}
1616

1717
public function testSupportsIfNotClassInstance()
1818
{
1919
$strategy = new ClassInstanceSupportStrategy('Symfony\Component\Workflow\Tests\SupportStrategy\Subject2');
2020

21-
$this->assertFalse($strategy->supports($this->getWorkflow(), new Subject1()));
21+
$this->assertFalse($strategy->supports($this->createWorkflow(), new Subject1()));
2222
}
2323

24-
private function getWorkflow()
24+
private function createWorkflow()
2525
{
2626
return $this->getMockBuilder(Workflow::class)
2727
->disableOriginalConstructor()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.