[Workflow] Finished integration of initial_marking + deprecated support for workflow + single state markin store

This commit is contained in:
Grégoire Pineau 2019-04-06 14:37:18 +02:00
parent 73708a61b6
commit 87839cfaf9
13 changed files with 43 additions and 186 deletions

View File

@ -282,8 +282,15 @@ class Configuration implements ConfigurationInterface
->fixXmlConfig('argument')
->children()
->enumNode('type')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "method" instead as it will be the only option in Symfony 5.0.')
->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.')
@ -296,7 +303,7 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->scalarNode('property')
->defaultNull()
->defaultValue('marking')
->end()
->scalarNode('service')
->cannotBeEmpty()
@ -310,10 +317,6 @@ class Configuration implements ConfigurationInterface
->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); })
->thenInvalid('"arguments" and "service" cannot be used together.')
->end()
->validate()
->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); })
->thenInvalid('"property" and "service" cannot be used together.')
->end()
->end()
->arrayNode('supports')
->beforeNormalization()

View File

@ -644,14 +644,15 @@ class FrameworkExtension extends Extension
// 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'] ?? 'marking',
$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']);
@ -676,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;
@ -687,6 +684,7 @@ 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 {

View File

@ -3,7 +3,13 @@
$container->loadFromExtension('framework', [
'workflows' => [
'legacy' => [
'type' => 'workflow',
'type' => 'state_machine',
'marking_store' => [
'type' => 'single_state',
'arguments' => [
'state',
],
],
'supports' => [
stdClass::class,
],

View File

@ -1,32 +0,0 @@
<?php
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'type' => 'workflow',
'marking_store' => [
'property' => 'states',
'service' => 'workflow_service',
],
'supports' => [
FrameworkExtensionTest::class,
],
'places' => [
'first',
'last',
],
'transitions' => [
'go' => [
'from' => [
'first',
],
'to' => [
'last',
],
],
],
],
],
]);

View File

@ -7,7 +7,10 @@
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 name="published" />

View File

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

View File

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

View File

@ -1,21 +0,0 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
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 property="multiple_state" service="workflow_service" />
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place name="first" />
<framework:place name="last" />
<framework:transition name="foobar">
<framework:from>a</framework:from>
<framework:to>a</framework:to>
</framework:transition>
</framework:workflow>
</framework:config>
</container>

View File

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

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

@ -1,17 +0,0 @@
framework:
workflows:
my_workflow:
marking_store:
property: state
service: workflow_service
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
places:
- first
- last
transitions:
go:
from:
- first
to:
- last

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));
@ -307,17 +310,6 @@ abstract class FrameworkExtensionTest extends TestCase
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "property" and "service" cannot be used together.
*/
public function testWorkflowCannotHaveBothPropertyAndService()
{
$this->createContainerFromFile('workflow_with_property_and_service');
}
/**
* @legacy
*
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "type" and "service" cannot be used together.
*/
@ -347,6 +339,7 @@ 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()
{
@ -423,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,78 +89,8 @@ 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 testWorkflowValidationMethodSingle()
{
$this->createContainerFromClosure(function ($container) {
$container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'method',
'arguments' => [
true,
],
],
'supports' => [
__CLASS__,
],
'places' => [
'a',
'b',
'c',
],
'transitions' => [
'a_to_b' => [
'from' => ['a'],
'to' => ['b', 'c'],
],
],
],
],
]);
});
}
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);
}
public function testWorkflowValidationMultipleState()
{
$this->createContainerFromClosure(function ($container) {
@ -197,6 +127,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()
{