Skip to content

Commit

Permalink
bug #51078 [FrameworkBundle][Workflow] Throw exception is workflow.xx…
Browse files Browse the repository at this point in the history
…x.transitions is not an array (lyrixx)

This PR was merged into the 5.4 branch.

Discussion
----------

[FrameworkBundle][Workflow] Throw exception is workflow.xxx.transitions is not an array

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

---

The following code raises a fatal error:
```yaml
framework:
    workflows:
        articles:
            transitions:
```

<details>

```
ErrorException:
Warning: foreach() argument must be of type array|object, null given

  at /home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/framework-bundle/DependencyInjection/Configuration.php:522
  at Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration->Symfony\Bundle\FrameworkBundle\DependencyInjection\{closure}()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/Builder/ExprBuilder.php:246)
  at Symfony\Component\Config\Definition\Builder\ExprBuilder::Symfony\Component\Config\Definition\Builder\{closure}()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/BaseNode.php:357)
  at Symfony\Component\Config\Definition\BaseNode->normalize()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/ArrayNode.php:292)
  at Symfony\Component\Config\Definition\ArrayNode->normalizeValue()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/BaseNode.php:385)
  at Symfony\Component\Config\Definition\BaseNode->normalize()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/PrototypedArrayNode.php:251)
  at Symfony\Component\Config\Definition\PrototypedArrayNode->normalizeValue()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/BaseNode.php:385)
  at Symfony\Component\Config\Definition\BaseNode->normalize()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/ArrayNode.php:292)
  at Symfony\Component\Config\Definition\ArrayNode->normalizeValue()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/BaseNode.php:385)
  at Symfony\Component\Config\Definition\BaseNode->normalize()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/ArrayNode.php:292)
  at Symfony\Component\Config\Definition\ArrayNode->normalizeValue()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/BaseNode.php:385)
  at Symfony\Component\Config\Definition\BaseNode->normalize()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/Processor.php:32)
  at Symfony\Component\Config\Definition\Processor->process()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/config/Definition/Processor.php:46)
  at Symfony\Component\Config\Definition\Processor->processConfiguration()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/dependency-injection/Extension/Extension.php:109)
  at Symfony\Component\DependencyInjection\Extension\Extension->processConfiguration()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/framework-bundle/DependencyInjection/FrameworkExtension.php:259)
  at Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension->load()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php:76)
  at Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/http-kernel/DependencyInjection/MergeExtensionConfigurationPass.php:45)
  at Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/dependency-injection/Compiler/Compiler.php:80)
  at Symfony\Component\DependencyInjection\Compiler\Compiler->compile()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/dependency-injection/ContainerBuilder.php:767)
  at Symfony\Component\DependencyInjection\ContainerBuilder->compile()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/http-kernel/Kernel.php:506)
  at Symfony\Component\HttpKernel\Kernel->initializeContainer()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/http-kernel/Kernel.php:757)
  at Symfony\Component\HttpKernel\Kernel->preBoot()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/http-kernel/Kernel.php:185)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/autoload_runtime.php:29)
  at require_once('/home/gregoire/dev/github.com/Faume-co/modules-shopify/vendor/autoload_runtime.php')
     (/home/gregoire/dev/github.com/Faume-co/modules-shopify/public/index.php:5)
```

</details>

Commits
-------

f585930 [FrameworkBundle][Workflow] Throw exception is workflow.xxx.transitions is not an array
  • Loading branch information
nicolas-grekas committed Jul 26, 2023
2 parents b69cde8 + f585930 commit fdf441d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 fdf441d

Please sign in to comment.