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 134a58b

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

18 files changed

+206
-25
lines changed

‎UPGRADE-3.3.md

Copy file name to clipboardExpand all lines: UPGRADE-3.3.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ TwigBridge
5959

6060
* The `TwigRendererEngine::setEnvironment()` method has been deprecated and will be removed
6161
in 4.0. Pass the Twig Environment as second argument of the constructor instead.
62+
63+
Workflow
64+
--------
65+
66+
* Deprecated class name support in `WorkflowRegistry::add()` as second parameter.
67+
Wrap the class name in an instance of ClassInstanceSupportStrategy instead.

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ FrameworkBundle
154154
* The `framework.serializer.cache` option and the services
155155
`serializer.mapping.cache.apc` and `serializer.mapping.cache.doctrine.apc`
156156
have been removed. APCu should now be automatically used when available.
157-
157+
158158
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been removed. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
159159

160160
SecurityBundle
@@ -216,7 +216,7 @@ Serializer
216216
* The ability to pass a Doctrine `Cache` instance to the `ClassMetadataFactory`
217217
class has been removed. You should use the `CacheClassMetadataFactory` class
218218
instead.
219-
219+
220220
* Not defining the 6th argument `$format = null` of the
221221
`AbstractNormalizer::instantiateObject()` method when overriding it is not
222222
supported anymore.
@@ -294,9 +294,9 @@ Validator
294294
// ...
295295
}
296296
```
297-
297+
298298
* The default value of the strict option of the `Choice` Constraint has been
299-
changed to `true` as of 4.0. If you need the previous behaviour ensure to
299+
changed to `true` as of 4.0. If you need the previous behaviour ensure to
300300
set the option to `false`.
301301

302302
Yaml
@@ -393,5 +393,10 @@ Yaml
393393

394394
Ldap
395395
----
396-
397-
* The `RenameEntryInterface` has been deprecated, and merged with `EntryManagerInterface`
396+
397+
* The `RenameEntryInterface` has been deprecated, and merged with `EntryManagerInterface`
398+
399+
Workflow
400+
--------
401+
402+
* Removed class name support in `WorkflowRegistry::add()` as second parameter.

‎src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Workflow\Definition;
1616
use Symfony\Component\Workflow\Marking;
1717
use Symfony\Component\Workflow\Registry;
18+
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
1819
use Symfony\Component\Workflow\Transition;
1920
use Symfony\Component\Workflow\Workflow;
2021

@@ -37,7 +38,7 @@ protected function setUp()
3738
$workflow = new Workflow($definition);
3839

3940
$registry = new Registry();
40-
$registry->add($workflow, \stdClass::class);
41+
$registry->add($workflow, new ClassInstanceSupportStrategy(\stdClass::class));
4142

4243
$this->extension = new WorkflowExtension($registry);
4344
}

‎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,13 +232,14 @@
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" />
236236
<xsd:element name="place" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
237237
<xsd:element name="transition" type="transition" minOccurs="1" maxOccurs="unbounded" />
238238
</xsd:sequence>
239239
<xsd:attribute name="name" type="xsd:string" use="required" />
240240
<xsd:attribute name="type" type="workflow_type" />
241241
<xsd:attribute name="initial-place" type="xsd:string" />
242+
<xsd:attribute name="support-strategy" type="xsd:string" />
242243
</xsd:complexType>
243244

244245
<xsd:complexType name="marking_store">
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,21 @@
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" support-strategy="foobar">
11+
<framework:marking-store type="multiple_state"/>
12+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
13+
<framework:place>first</framework:place>
14+
<framework:place>last</framework:place>
15+
<framework:transition name="foobar">
16+
<framework:from>a</framework:from>
17+
<framework:to>a</framework:to>
18+
</framework:transition>
19+
</framework:workflow>
20+
</framework:config>
21+
</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.
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
CHANGELOG
22
=========
3+
4+
3.3.0
5+
-----
6+
7+
* Deprecated class name support in `WorkflowRegistry::add()` as second parameter.
8+
Wrap the class name in an instance of ClassInstanceSupportStrategy instead.

‎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.