feature #30890 [Workflow] Changed initial_places to initial_marking, added property (HeahDude, lyrixx)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Workflow] Changed initial_places to initial_marking, added property

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #30662 and #30656
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony/issues/30656

EUFOSSA

---

* [Workflow] Changed initial_places to initial_marking, added property instead of type
* [Workflow] Finished integration of initial_marking + deprecated support for workflow + single state markin store
 [Workflow] Deprecate worflow and single state marking

---

Here is an exemple of deprecation:
```

  3x: Passing something else than "method" has been deprecated in Symfony 4.3.
    1x in PhpFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
    1x in XmlFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
    1x in YamlFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection

  3x: The "framework.workflows.workflows.legacy.marking_store.arguments" configuration key has been deprecated in Symfony 4.3. Use "property" instead.
    1x in PhpFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
    1x in XmlFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
    1x in YamlFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection

  3x: The "framework.workflows.workflows.legacy.initial_place" configuration key has been deprecated in Symfony 4.3, use the "initial_marking" configuration key instead.
    1x in PhpFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
    1x in XmlFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
    1x in YamlFrameworkExtensionTest::testWorkflowLegacy from Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection
  ```

Commits
-------

039353546f [Workflow] Deprecate worflow and single state marking
87839cfaf9 [Workflow] Finished integration of initial_marking + deprecated support for workflow + single state markin store
73708a61b6 [Workflow] Changed initial_places to initial_marking, added property instead of type
This commit is contained in:
Fabien Potencier 2019-04-06 18:42:29 +02:00
commit ede66604d7
37 changed files with 228 additions and 167 deletions

View File

@ -166,11 +166,6 @@ Workflow
initial_places: [draft]
```
Yaml
----
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
Workflow
--------
@ -202,19 +197,22 @@ Workflow
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
type: multiple
arguments: states
```
After:
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
type: method
property: states
```
* `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
@ -225,7 +223,30 @@ Workflow
workflows:
article:
marking_store:
type: single
arguments: state
```
After:
```yaml
framework:
workflows:
type: state_machine
article:
marking_store:
type: method
property: state
```
* Using a workflow with a single state marking is deprecated. Use a state machine instead.
Before:
```yaml
framework:
workflows:
article:
type: workflow
marking_store:
type: single_state
```
After:
@ -233,8 +254,13 @@ Workflow
framework:
workflows:
article:
type: state_machine
marking_store:
# type: single_state # Since the single_state marking store is deprecated, use method instead
type: method
arguments:
- true
```
Yaml
----
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.

View File

@ -388,8 +388,68 @@ Workflow
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
* Removed support of `initial_place`. Use `initial_places` instead.
* `MultipleStateMarkingStore` has been removed.
* `SingleStateMarkingStore` has been removed.
* `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.
Before:
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
type: multiple
arguments: states
```
After:
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
property: states
```
* `SingleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.
Before:
```yaml
framework:
workflows:
article:
marking_store:
arguments: state
```
After:
```yaml
framework:
workflows:
article:
marking_store:
property: state
```
* Support for using a workflow with a single state marking is dropped. Use a state machine instead.
Before:
```yaml
framework:
workflows:
article:
type: workflow
marking_store:
type: single_state
```
After:
```yaml
framework:
workflows:
article:
type: state_machine
```
Yaml
----

View File

@ -233,7 +233,7 @@ class Configuration implements ConfigurationInterface
$workflows = [];
}
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_places', 'places', 'transitions']))) {
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_marking', 'places', 'transitions']))) {
$workflows = $workflows['workflows'];
}
@ -258,9 +258,17 @@ class Configuration implements ConfigurationInterface
->arrayNode('workflows')
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
->always(function ($v) {
if (isset($v['initial_place'])) {
$v['initial_marking'] = [$v['initial_place']];
}
return $v;
})
->end()
->fixXmlConfig('support')
->fixXmlConfig('place')
->fixXmlConfig('initial_place')
->fixXmlConfig('transition')
->children()
->arrayNode('audit_trail')
@ -275,8 +283,17 @@ class Configuration implements ConfigurationInterface
->children()
->enumNode('type')
->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.')
->beforeNormalization()
->ifString()
->then(function ($v) { return [$v]; })
@ -285,6 +302,9 @@ class Configuration implements ConfigurationInterface
->prototype('scalar')
->end()
->end()
->scalarNode('property')
->defaultValue('marking')
->end()
->scalarNode('service')
->cannotBeEmpty()
->end()
@ -315,10 +335,10 @@ class Configuration implements ConfigurationInterface
->cannotBeEmpty()
->end()
->scalarNode('initial_place')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_places" configuration key instead.')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_marking" configuration key instead.')
->defaultNull()
->end()
->arrayNode('initial_places')
->arrayNode('initial_marking')
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return [$v]; })
@ -454,6 +474,16 @@ class Configuration implements ConfigurationInterface
})
->thenInvalid('"supports" or "support_strategy" should be configured.')
->end()
->validate()
->ifTrue(function ($v) {
return 'workflow' === $v['type'] && 'single_state' === ($v['marking_store']['type'] ?? false);
})
->then(function ($v) {
@trigger_error('Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead.', E_USER_DEPRECATED);
return $v;
})
->end()
->end()
->end()
->end()

View File

@ -631,21 +631,28 @@ class FrameworkExtension extends Extension
// Create places
$places = array_column($workflow['places'], 'name');
$initialPlaces = $workflow['initial_places'] ?? $workflow['initial_place'] ?? [];
$initialMarking = $workflow['initial_marking'] ?? $workflow['initial_place'] ?? [];
// Create a Definition
$definitionDefinition = new Definition(Workflow\Definition::class);
$definitionDefinition->setPublic(false);
$definitionDefinition->addArgument($places);
$definitionDefinition->addArgument($transitions);
$definitionDefinition->addArgument($initialPlaces);
$definitionDefinition->addArgument($initialMarking);
$definitionDefinition->addArgument($metadataStoreDefinition);
// 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'],
]);
} else {
foreach ($workflow['marking_store']['arguments'] as $argument) {
$markingStoreDefinition->addArgument($argument);
}
}
} elseif (isset($workflow['marking_store']['service'])) {
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
@ -670,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;
@ -681,12 +684,13 @@ 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 {
return $container->get((string) $ref);
}, $transitions))
->setInitialPlace($initialPlaces)
->setInitialPlace($initialMarking)
->build()
;
$validator->validate($realDefinition, $name);

View File

@ -279,7 +279,7 @@
<xsd:complexType name="workflow">
<xsd:sequence>
<xsd:element name="initial-place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="initial-marking" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
@ -289,6 +289,7 @@
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="workflow_type" />
<xsd:attribute name="initial-place" type="xsd:string" />
<xsd:attribute name="initial-marking" type="xsd:string" />
<xsd:attribute name="support-strategy" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>
@ -304,12 +305,14 @@
</xsd:sequence>
<xsd:attribute name="type" type="marking_store_type" />
<xsd:attribute name="service" type="xsd:string" />
<xsd:attribute name="property" type="xsd:string" />
</xsd:complexType>
<xsd:simpleType name="marking_store_type">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="multiple_state" />
<xsd:enumeration value="single_state" />
<xsd:enumeration value="method" />
</xsd:restriction>
</xsd:simpleType>

View File

@ -1,11 +1,15 @@
<?php
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
$container->loadFromExtension('framework', [
'workflows' => [
'legacy' => [
'type' => 'workflow',
'type' => 'state_machine',
'marking_store' => [
'type' => 'single_state',
'arguments' => [
'state',
],
],
'supports' => [
stdClass::class,
],

View File

@ -6,7 +6,7 @@ $container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
'type' => 'method',
'service' => 'workflow_service',
],
'supports' => [

View File

@ -6,13 +6,10 @@ $container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'multiple_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['draft'],
'initial_marking' => ['draft'],
'places' => [
'draft',
'wait_for_journalist',

View File

@ -6,13 +6,10 @@ $container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'multiple_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['draft'],
'initial_marking' => ['draft'],
'places' => [
'draft',
'wait_for_journalist',

View File

@ -5,9 +5,7 @@ use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionT
$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
],
'type' => 'workflow',
'supports' => [
FrameworkExtensionTest::class,
],

View File

@ -1,13 +1,9 @@
<?php
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
],
'type' => 'workflow',
'places' => [
'first',
'last',

View File

@ -6,13 +6,10 @@ $container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'multiple_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['draft'],
'initial_marking' => ['draft'],
'places' => [
'draft',
'wait_for_journalist',
@ -41,13 +38,10 @@ $container->loadFromExtension('framework', [
],
],
'pull_request' => [
'marking_store' => [
'type' => 'single_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['start'],
'initial_marking' => 'start',
'metadata' => [
'title' => 'workflow title',
],

View File

@ -6,7 +6,7 @@ $container->loadFromExtension('framework', [
'foo' => [
'type' => 'workflow',
'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'],
'initial_places' => ['bar'],
'initial_marking' => ['bar'],
'places' => ['bar', 'baz'],
'transitions' => [
'bar_baz' => [

View File

@ -6,7 +6,7 @@ $container->loadFromExtension('framework', [
'workflows' => [
'type' => 'workflow',
'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'],
'initial_places' => ['bar'],
'initial_marking' => ['bar'],
'places' => ['bar', 'baz'],
'transitions' => [
'bar_baz' => [

View File

@ -7,10 +7,13 @@
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow name="legacy" type="workflow" initial-place="draft">
<framework:workflow name="legacy" type="state_machine" initial-place="draft">
<framework:marking-store type="single_state">
<framework:argument>state</framework:argument>
</framework:marking-store>
<framework:support>stdClass</framework:support>
<framework:place name="draft"></framework:place>
<framework:place name="published"></framework:place>
<framework:place name="draft" />
<framework:place name="published" />
<framework:transition name="publish">
<framework:from>draft</framework:from>
<framework:to>published</framework:to>

View File

@ -8,7 +8,7 @@
<framework:config>
<framework:workflow name="my_workflow">
<framework:marking-store type="multiple_state" service="workflow_service" />
<framework:marking-store type="method" service="workflow_service" />
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place name="first" />
<framework:place name="last" />

View File

@ -8,11 +8,7 @@
<framework:config>
<framework:workflow name="article" type="workflow">
<framework:initial-place>draft</framework:initial-place>
<framework:marking-store type="multiple_state">
<framework:argument>a</framework:argument>
<framework:argument>a</framework:argument>
</framework:marking-store>
<framework:initial-marking>draft</framework:initial-marking>
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>draft</framework:place>
<framework:place>wait_for_journalist</framework:place>

View File

@ -8,11 +8,7 @@
<framework:config>
<framework:workflow name="article" type="workflow">
<framework:initial-place>draft</framework:initial-place>
<framework:marking-store type="multiple_state">
<framework:argument>a</framework:argument>
<framework:argument>a</framework:argument>
</framework:marking-store>
<framework:initial-marking>draft</framework:initial-marking>
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place name="draft" />
<framework:place name="wait_for_journalist" />

View File

@ -7,8 +7,7 @@
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow name="my_workflow" support-strategy="foobar">
<framework:marking-store type="multiple_state"/>
<framework:workflow name="my_workflow" support-strategy="foobar" type="workflow">
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place name="first" />
<framework:place name="last" />

View File

@ -7,8 +7,7 @@
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow name="my_workflow">
<framework:marking-store type="multiple_state"/>
<framework:workflow name="my_workflow" type="workflow">
<framework:place name="first" />
<framework:place name="last" />
<framework:transition name="foobar">

View File

@ -8,18 +8,15 @@
<framework:config>
<framework:workflow name="article" type="workflow">
<framework:initial-place>draft</framework:initial-place>
<framework:marking-store type="multiple_state">
<framework:argument>a</framework:argument>
<framework:argument>a</framework:argument>
</framework:marking-store>
<framework:initial-marking>draft</framework:initial-marking>
<framework:marking-store type="method" property="state" />
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place name="draft"></framework:place>
<framework:place name="wait_for_journalist"></framework:place>
<framework:place name="approved_by_journalist"></framework:place>
<framework:place name="wait_for_spellchecker"></framework:place>
<framework:place name="approved_by_spellchecker"></framework:place>
<framework:place name="published"></framework:place>
<framework:place name="draft" />
<framework:place name="wait_for_journalist" />
<framework:place name="approved_by_journalist" />
<framework:place name="wait_for_spellchecker" />
<framework:place name="approved_by_spellchecker" />
<framework:place name="published" />
<framework:transition name="request_review">
<framework:from>draft</framework:from>
<framework:to>wait_for_journalist</framework:to>
@ -40,8 +37,8 @@
</framework:transition>
</framework:workflow>
<framework:workflow name="pull_request" initial-place="start">
<framework:marking-store type="single_state"/>
<framework:workflow name="pull_request">
<framework:initial-marking>start</framework:initial-marking>
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place name="start">
<framework:metadata>

View File

@ -6,8 +6,7 @@
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow enabled="true" name="foo" type="workflow">
<framework:initial-place>bar</framework:initial-place>
<framework:workflow enabled="true" name="foo" type="workflow" initial-marking="start">
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>bar</framework:place>
<framework:place>baz</framework:place>

View File

@ -7,7 +7,7 @@
<framework:config>
<framework:workflow enabled="true" name="workflows" type="workflow">
<framework:initial-place>bar</framework:initial-place>
<framework:initial-marking>bar</framework:initial-marking>
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>bar</framework:place>
<framework:place>baz</framework:place>

View File

@ -1,7 +1,11 @@
framework:
workflows:
legacy:
type: workflow
type: state_machine
marking_store:
type: single_state
arguments:
- state
initial_place: draft
supports:
- stdClass

View File

@ -2,7 +2,7 @@ framework:
workflows:
my_workflow:
marking_store:
type: multiple_state
type: method
service: workflow_service
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest

View File

@ -2,18 +2,16 @@ framework:
workflows:
article:
type: workflow
marking_store:
type: multiple_state
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_places: [draft]
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_marking: [draft]
places:
- draft
- wait_for_journalist
- approved_by_journalist
- wait_for_spellchecker
- approved_by_spellchecker
- published
- draft
- wait_for_journalist
- approved_by_journalist
- wait_for_spellchecker
- approved_by_spellchecker
- published
transitions:
request_review:
from: [draft]

View File

@ -2,11 +2,9 @@ framework:
workflows:
article:
type: workflow
marking_store:
type: multiple_state
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_places: [draft]
initial_marking: [draft]
places:
- draft
- wait_for_journalist

View File

@ -1,8 +1,7 @@
framework:
workflows:
my_workflow:
marking_store:
type: multiple_state
type: workflow
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
support_strategy: foobar

View File

@ -1,8 +1,7 @@
framework:
workflows:
my_workflow:
marking_store:
type: multiple_state
type: workflow
places:
- first
- last

View File

@ -2,11 +2,9 @@ framework:
workflows:
article:
type: workflow
marking_store:
type: multiple_state
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_places: [draft]
initial_marking: [draft]
places:
# simple format
- draft
@ -29,11 +27,9 @@ framework:
from: [approved_by_journalist, approved_by_spellchecker]
to: [published]
pull_request:
marking_store:
type: single_state
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_places: [start]
initial_marking: start
metadata:
title: workflow title
places:

View File

@ -6,7 +6,7 @@ framework:
type: workflow
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_places: [bar]
initial_marking: [bar]
places:
- bar
- baz

View File

@ -5,7 +5,7 @@ framework:
type: workflow
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_places: [bar]
initial_marking: [bar]
places:
- bar
- baz

View File

@ -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));
@ -312,7 +315,7 @@ abstract class FrameworkExtensionTest extends TestCase
*/
public function testWorkflowCannotHaveBothTypeAndService()
{
$this->createContainerFromFile('workflow_with_type_and_service');
$this->createContainerFromFile('workflow_legacy_with_type_and_service');
}
/**
@ -336,10 +339,11 @@ 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()
{
$this->createContainerFromFile('workflow_with_arguments_and_service');
$this->createContainerFromFile('workflow_legacy_with_arguments_and_service');
}
public function testWorkflowMultipleTransitionsWithSameName()
@ -412,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');

View File

@ -89,10 +89,10 @@ 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
* @expectedDeprecation Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead.
*/
public function testWorkflowValidationMethodSingle()
public function testWorkflowDeprecateWorkflowSingleState()
{
$this->createContainerFromClosure(function ($container) {
$container->loadFromExtension('framework', [
@ -100,10 +100,7 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'method',
'arguments' => [
true,
],
'type' => 'single_state',
],
'supports' => [
__CLASS__,
@ -116,7 +113,7 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest
'transitions' => [
'a_to_b' => [
'from' => ['a'],
'to' => ['b', 'c'],
'to' => ['b'],
],
],
],
@ -125,42 +122,9 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest
});
}
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);
}
/**
* @group legacy
*/
public function testWorkflowValidationMultipleState()
{
$this->createContainerFromClosure(function ($container) {
@ -197,6 +161,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()
{