-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Workflow] Added new validator to make sure each place has unique translation names #21271
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Symfony/Component/Workflow/Tests/Validator/UniqueTransitionNameValidatorTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Workflow\Tests\Validator; | ||
|
||
use Symfony\Component\Workflow\Definition; | ||
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait; | ||
use Symfony\Component\Workflow\Transition; | ||
use Symfony\Component\Workflow\Validator\UniqueTransitionNameValidator; | ||
|
||
class UniqueTransitionNameValidatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use WorkflowBuilderTrait; | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException | ||
* @expectedExceptionMessage All transitions for a place must have an unique name. Multiple transitions named "t1" where found for place "a" in workflow "foo". | ||
*/ | ||
public function testWorkflowWithInvalidNames() | ||
{ | ||
$places = range('a', 'c'); | ||
|
||
$transitions = array(); | ||
$transitions[] = new Transition('t1', 'a', 'b'); | ||
$transitions[] = new Transition('t1', 'a', 'c'); | ||
|
||
$definition = new Definition($places, $transitions); | ||
|
||
(new UniqueTransitionNameValidator())->validate($definition, 'foo'); | ||
} | ||
|
||
public function testSameTransitionNameButNotSamePlace() | ||
{ | ||
$places = range('a', 'd'); | ||
|
||
$transitions = array(); | ||
$transitions[] = new Transition('t1', 'a', 'b'); | ||
$transitions[] = new Transition('t1', 'b', 'c'); | ||
$transitions[] = new Transition('t1', 'd', 'c'); | ||
|
||
$definition = new Definition($places, $transitions); | ||
|
||
(new UniqueTransitionNameValidator())->validate($definition, 'foo'); | ||
} | ||
|
||
public function testValidWorkflow() | ||
{ | ||
$definition = $this->createSimpleWorkflowDefinition(); | ||
|
||
(new UniqueTransitionNameValidator())->validate($definition, 'foo'); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Symfony/Component/Workflow/Validator/UniqueTransitionNameValidator.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\Validator; | ||
|
||
use Symfony\Component\Workflow\Definition; | ||
use Symfony\Component\Workflow\Exception\InvalidDefinitionException; | ||
|
||
/** | ||
* Make sure all transitions for one place has unique name. | ||
* | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
class UniqueTransitionNameValidator implements DefinitionValidatorInterface | ||
{ | ||
public function validate(Definition $definition, $name) | ||
{ | ||
$places = array_fill_keys($definition->getPlaces(), array()); | ||
foreach ($definition->getTransitions() as $transition) { | ||
foreach ($transition->getFroms() as $from) { | ||
if (in_array($transition->getName(), $places[$from])) { | ||
throw new InvalidDefinitionException(sprintf('All transitions for a place must have an unique name. Multiple transitions named "%s" where found for place "%s" in workflow "%s".', $transition->getName(), $from, $name)); | ||
} | ||
$places[$from][] = $transition->getName(); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing composer.json update I guess, for ^3.2.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reference to symfony/workflow at all in the composer.json of the framework bundle. Should I still add one?