Skip to content

[Workflow] improve workflow config validation #20482

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 1 commit into from
Nov 16, 2016

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Nov 10, 2016

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

@xabbuh
Copy link
Member Author

xabbuh commented Nov 10, 2016

We should add some tests too.

Status: Needs work

@xabbuh
Copy link
Member Author

xabbuh commented Nov 10, 2016

Tests added

Status: Needs review

->thenInvalid('"type" and "service" cannot be used together.')
->end()
->validate()
->ifTrue(function ($v) { return isset($v['arguments']) && isset($v['service']); })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should check whether arguments is an empty array or no actually, to account for people repeating the default value of the node explicitly (needed if they overwrite the definition in a subsequent file). An empty array should not trigger the exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. However, what do you think about adding a constraint to the arguments node instead forbidding to configure it as an empty list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty array is a valid value (and it is the default value of the node btw, as it is a prototyped array node)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot confirm that. requiresAtLeastOneElement() works as expected when playing with the fixtures I added in this PR.

</framework:marking-store>
<framework:supports>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:supports>
<framework:places>first</framework:places>
<framework:places>last</framework:places>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the XML should be improved. This should be place, not places.

The Configuration class actually misses the necessary fixXmlConfig calls for workflows, places and transitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #20458 which addresses most of the requested changes

<framework:supports>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:supports>
<framework:places>first</framework:places>
<framework:places>last</framework:places>
<framework:transitions>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this node should not exist in the XML. It is not consistent with the way things work elsewhere.

<framework:workflow name="my_workflow">
<framework:marking-store>
<framework:type>multiple_state</framework:type>
<framework:service>workflow_service</framework:service>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be attributes, not subnodes

http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:workflows>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this node should not exist either

@stof
Copy link
Member

stof commented Nov 11, 2016

If you are not comfortable with the XML config format, I can submit a separate PR instead to fix it.

@xabbuh xabbuh force-pushed the workflow-config-validation branch from 2133aba to 945f618 Compare November 11, 2016 10:27
@javiereguiluz javiereguiluz added this to the 3.2 milestone Nov 11, 2016

return $v;
})
->ifTrue(function ($v) { return !isset($v['type']) && !isset($v['service']); })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I my previous PR, I added that too. But I realized it's not mandatory. If nothing is configured, we don't give a MarkingStore to the workflow, and so the workflow will use the default MarkingStore. So it makes the configuration simpler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I reverted this change.

@xabbuh xabbuh force-pushed the workflow-config-validation branch from 945f618 to 329fdb0 Compare November 14, 2016 09:39
@lyrixx
Copy link
Member

lyrixx commented Nov 15, 2016

@xabbuh I have merged other PRs relative to the configuration. Could you rebase this one? Thanks ;)

@xabbuh
Copy link
Member Author

xabbuh commented Nov 15, 2016

@lyrixx Should I wait for #20458 to avoid rebasing twice or do you prefer to merge here first?

@lyrixx
Copy link
Member

lyrixx commented Nov 15, 2016

Indeed. I forget the other one. I prefer to wait another +1 there before the merge.

@xabbuh xabbuh force-pushed the workflow-config-validation branch from 329fdb0 to 3f94d16 Compare November 16, 2016 08:10
@stof
Copy link
Member

stof commented Nov 16, 2016

I merged #20458 so please update your XML fixtures

@xabbuh xabbuh force-pushed the workflow-config-validation branch from 3f94d16 to b1fb2a4 Compare November 16, 2016 08:45
@xabbuh
Copy link
Member Author

xabbuh commented Nov 16, 2016

I rebased and updated the XML fixtures.

@lyrixx
Copy link
Member

lyrixx commented Nov 16, 2016

👍

@lyrixx
Copy link
Member

lyrixx commented Nov 16, 2016

Thank you @xabbuh.

@lyrixx lyrixx merged commit b1fb2a4 into symfony:master Nov 16, 2016
lyrixx added a commit that referenced this pull request Nov 16, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Workflow] improve workflow config validation

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

b1fb2a4 [Workflow] improve workflow config validation
@xabbuh xabbuh deleted the workflow-config-validation branch November 16, 2016 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants