|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Workflow\Tests\DependencyInjection; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | +use Symfony\Component\Workflow\Definition; |
| 17 | +use Symfony\Component\Workflow\DependencyInjection\WorkflowValidatorPass; |
| 18 | +use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface; |
| 19 | +use Symfony\Component\Workflow\WorkflowInterface; |
| 20 | + |
| 21 | +class WorkflowValidatorPassTest extends TestCase |
| 22 | +{ |
| 23 | + private ContainerBuilder $container; |
| 24 | + private WorkflowValidatorPass $compilerPass; |
| 25 | + |
| 26 | + protected function setUp(): void |
| 27 | + { |
| 28 | + $this->container = new ContainerBuilder(); |
| 29 | + $this->compilerPass = new WorkflowValidatorPass(); |
| 30 | + } |
| 31 | + |
| 32 | + public function testNothingToDo() |
| 33 | + { |
| 34 | + $this->compilerPass->process($this->container); |
| 35 | + |
| 36 | + $this->assertFalse(DefinitionValidator::$called); |
| 37 | + } |
| 38 | + |
| 39 | + public function testValidate() |
| 40 | + { |
| 41 | + $this |
| 42 | + ->container |
| 43 | + ->register('my.workflow', WorkflowInterface::class) |
| 44 | + ->addTag('workflow', [ |
| 45 | + 'definition_id' => 'my.workflow.definition', |
| 46 | + 'name' => 'my.workflow', |
| 47 | + 'definition_validators' => [DefinitionValidator::class], |
| 48 | + ]) |
| 49 | + ; |
| 50 | + |
| 51 | + $this |
| 52 | + ->container |
| 53 | + ->register('my.workflow.definition', Definition::class) |
| 54 | + ->setArguments([ |
| 55 | + '$places' => [], |
| 56 | + '$transitions' => [], |
| 57 | + ]) |
| 58 | + ; |
| 59 | + |
| 60 | + $this->compilerPass->process($this->container); |
| 61 | + |
| 62 | + $this->assertTrue(DefinitionValidator::$called); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +class DefinitionValidator implements DefinitionValidatorInterface |
| 67 | +{ |
| 68 | + public static bool $called = false; |
| 69 | + |
| 70 | + public function validate(Definition $definition, string $name): void |
| 71 | + { |
| 72 | + self::$called = true; |
| 73 | + } |
| 74 | +} |
0 commit comments