Skip to content

Commit

Permalink
[FrameworkBundle][Workflow] Throw exception is workflow.xxx.transitio…
Browse files Browse the repository at this point in the history
…ns is not an array
  • Loading branch information
lyrixx committed Jul 24, 2023
1 parent 0bc39e8 commit f585930
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Expand Up @@ -446,6 +446,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->beforeNormalization()
->always()
->then(function ($places) {
if (!\is_array($places)) {
throw new InvalidConfigurationException('The "places" option must be an array in workflow configuration.');
}

// It's an indexed array of shape ['place1', 'place2']
if (isset($places[0]) && \is_string($places[0])) {
return array_map(function (string $place) {
Expand Down Expand Up @@ -491,6 +495,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->beforeNormalization()
->always()
->then(function ($transitions) {
if (!\is_array($transitions)) {
throw new InvalidConfigurationException('The "transitions" option must be an array in workflow configuration.');
}

// It's an indexed array, we let the validation occur
if (isset($transitions[0]) && \is_array($transitions[0])) {
return $transitions;
Expand Down
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;

use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
Expand Down Expand Up @@ -56,6 +57,36 @@ public function testAssetPackageCannotHavePathAndUrl()
});
}

public function testWorkflowValidationPlacesIsArray()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The "places" option must be an array in workflow configuration.');
$this->createContainerFromClosure(function ($container) {
$container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'places' => null,
],
],
]);
});
}

public function testWorkflowValidationTransitonsIsArray()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The "transitions" option must be an array in workflow configuration.');
$this->createContainerFromClosure(function ($container) {
$container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'transitions' => null,
],
],
]);
});
}

public function testWorkflowValidationStateMachine()
{
$this->expectException(InvalidDefinitionException::class);
Expand Down

0 comments on commit f585930

Please sign in to comment.