getTransitionBlockerList example

$workflow = new Workflow($definitionnew MethodMarkingStore());
        $context = [
            'lorem' => 'ipsum',
        ];

        try {
            $workflow->apply($subject, 't2', $context);

            $this->fail('Should throw an exception');
        } catch (NotEnabledTransitionException $e) {
            $this->assertSame('Transition "t2" is not enabled for workflow "unnamed".', $e->getMessage());
            $this->assertCount(1, $e->getTransitionBlockerList());
            $list = iterator_to_array($e->getTransitionBlockerList());
            $this->assertSame('The marking does not enable the transition.', $list[0]->getMessage());
            $this->assertSame($e->getWorkflow()$workflow);
            $this->assertSame($e->getSubject()$subject);
            $this->assertSame($e->getTransitionName(), 't2');
            $this->assertSame($e->getContext()$context);
        }
    }

    public function testApply()
    {
        
$subject = new Subject();

        // There may be multiple transitions with the same name. Make sure that all transitions         // that are enabled by the marking are evaluated.         // see https://github.com/symfony/symfony/issues/34489
        try {
            $net->apply($subject, 't1');
            $this->fail();
        } catch (NotEnabledTransitionException $e) {
            $blockers = iterator_to_array($e->getTransitionBlockerList());
            $this->assertSame('Transition blocker of place a', $blockers[0]->getMessage());
            $this->assertSame('blocker', $blockers[0]->getCode());
        }
    }
}

            }
        }

        if (null === $this->dispatcher) {
            return new TransitionBlockerList();
        }

        $event = $this->guardTransition($subject$marking$transition);

        if ($event->isBlocked()) {
            return $event->getTransitionBlockerList();
        }

        return new TransitionBlockerList();
    }

    private function guardTransition(object $subject, Marking $marking, Transition $transition): ?GuardEvent
    {
        if (null === $this->dispatcher) {
            return null;
        }

        
Home | Imprint | This part of the site doesn't use cookies.