Skip to content

[Workflow] Changed initial_places to initial_marking, added property #30890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Workflow] Finished integration of initial_marking + deprecated suppo…
…rt for workflow + single state markin store
  • Loading branch information
lyrixx committed Apr 6, 2019
commit 87839cfaf94e3a6b426036b7ab63b80ef89a6fe0
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->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.')
Expand All @@ -296,7 +303,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->end()
->end()
->scalarNode('property')
->defaultNull()
->defaultValue('marking')
->end()
->scalarNode('service')
->cannotBeEmpty()
Expand All @@ -310,10 +317,6 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,15 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
// 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']);
Expand All @@ -676,17 +677,14 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
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;
case 'multiple_state' === ($workflow['marking_store']['type'] ?? false):
$validator = new Workflow\Validator\WorkflowValidator(false);
break;
}

if ($validator) {
$realDefinition = (new Workflow\DefinitionBuilder($places))
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
$container->loadFromExtension('framework', [
'workflows' => [
'legacy' => [
'type' => 'workflow',
'type' => 'state_machine',
'marking_store' => [
'type' => 'single_state',
'arguments' => [
'state',
],
],
'supports' => [
stdClass::class,
],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
framework:
workflows:
legacy:
type: workflow
type: state_machine
marking_store:
type: single_state
arguments:
- state
initial_place: draft
supports:
- stdClass
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,18 @@ public function testWorkflows()
$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));

Expand All @@ -307,17 +310,6 @@ public function testWorkflowAreValidated()
}

/**
* @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.
*/
Expand Down Expand Up @@ -347,6 +339,7 @@ public function testWorkflowShouldHaveOneOfSupportsAndSupportStrategy()
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage "arguments" and "service" cannot be used together.
* @group legacy
*/
public function testWorkflowCannotHaveBothArgumentsAndService()
{
Expand Down Expand Up @@ -423,7 +416,7 @@ public function testWorkflowMultipleTransitionsWithSameName()
], $container->getDefinition($transitions[4])->getArguments());
}

public function testGuardExpressions()
public function testWorkflowGuardExpressions()
{
$container = $this->createContainerFromFile('workflow_with_guard_expression');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,78 +89,8 @@ public function testWorkflowValidationStateMachine()
}

/**
* @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) {
Expand Down Expand Up @@ -197,6 +127,7 @@ public function testWorkflowValidationMultipleState()
/**
* @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()
{
Expand Down