WorkflowValidator example

$this->expectException(InvalidDefinitionException::class);
        $this->expectExceptionMessage('All transitions for a place must have an unique name. Multiple transitions named "t1" where found for place "a" in workflow "foo".');
        $places = range('a', 'c');

        $transitions = [];
        $transitions[] = new Transition('t0', 'c', 'b');
        $transitions[] = new Transition('t1', 'a', 'b');
        $transitions[] = new Transition('t1', 'a', 'c');

        $definition = new Definition($places$transitions);

        (new WorkflowValidator())->validate($definition, 'foo');
    }

    public function testSameTransitionNameButNotSamePlace()
    {
        $places = range('a', 'd');

        $transitions = [];
        $transitions[] = new Transition('t1', 'a', 'b');
        $transitions[] = new Transition('t1', 'b', 'c');
        $transitions[] = new Transition('t1', 'd', 'c');

        
// Store to container             $container->setDefinition($workflowId$workflowDefinition);
            $container->setDefinition(sprintf('%s.definition', $workflowId)$definitionDefinition);
            $container->registerAliasForArgument($workflowId, WorkflowInterface::class$name.'.'.$type);
            $container->registerAliasForArgument($workflowId, WorkflowInterface::class$name);

            // Validate Workflow             if ('state_machine' === $workflow['type']) {
                $validator = new Workflow\Validator\StateMachineValidator();
            } else {
                $validator = new Workflow\Validator\WorkflowValidator();
            }

            $trs = array_map(fn (Reference $ref): Workflow\Transition => $container->get((string) $ref)$transitions);
            $realDefinition = new Workflow\Definition($places$trs$initialMarking);
            $validator->validate($realDefinition$name);

            // Add workflow to Registry             if ($workflow['supports']) {
                foreach ($workflow['supports'] as $supportedClassName) {
                    $strategyDefinition = new Definition(Workflow\SupportStrategy\InstanceOfSupportStrategy::class[$supportedClassName]);
                    $registryDefinition->addMethodCall('addWorkflow', [new Reference($workflowId)$strategyDefinition]);
                }
Home | Imprint | This part of the site doesn't use cookies.