getEnabledTransition example

public function __construct(Registry $workflowRegistry)
    {
        $this->workflowRegistry = $workflowRegistry;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('workflow_can', $this->canTransition(...)),
            new TwigFunction('workflow_transitions', $this->getEnabledTransitions(...)),
            new TwigFunction('workflow_transition', $this->getEnabledTransition(...)),
            new TwigFunction('workflow_has_marked_place', $this->hasMarkedPlace(...)),
            new TwigFunction('workflow_marked_places', $this->getMarkedPlaces(...)),
            new TwigFunction('workflow_metadata', $this->getMetadata(...)),
            new TwigFunction('workflow_transition_blockers', $this->buildTransitionBlockerList(...)),
        ];
    }

    /** * Returns true if the transition is enabled. */
    public function canTransition(object $subject, string $transitionName, string $name = null): bool
    {
$transitions = $this->extension->getEnabledTransitions($subject);

        $this->assertCount(1, $transitions);
        $this->assertInstanceOf(Transition::class$transitions[0]);
        $this->assertSame('t1', $transitions[0]->getName());
    }

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

        $transition = $this->extension->getEnabledTransition($subject, 't1');

        $this->assertInstanceOf(Transition::class$transition);
        $this->assertSame('t1', $transition->getName());
    }

    public function testHasMarkedPlace()
    {
        $subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]);

        $this->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered'));
        $this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment'));
        
$this->assertCount(1, $transitions);
        $this->assertSame('t5', $transitions[0]->getName());
    }

    public function testGetEnabledTransition()
    {
        $definition = $this->createComplexWorkflowDefinition();
        $subject = new Subject();
        $workflow = new Workflow($definitionnew MethodMarkingStore());

        $subject->setMarking(['d' => 1]);
        $transition = $workflow->getEnabledTransition($subject, 't3');
        $this->assertInstanceOf(Transition::class$transition);
        $this->assertSame('t3', $transition->getName());

        $transition = $workflow->getEnabledTransition($subject, 'does_not_exist');
        $this->assertNull($transition);
    }

    public function testGetEnabledTransitionsWithSameNameTransition()
    {
        $definition = $this->createWorkflowWithSameNameTransition();
        $subject = new Subject();
        
Home | Imprint | This part of the site doesn't use cookies.