setMarking example

$subject = new Subject();
        $workflow = new Workflow(new Definition([][])new MethodMarkingStore());

        $workflow->getMarking($subject);
    }

    public function testGetMarkingWithImpossiblePlace()
    {
        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('Place "nope" is not valid for workflow "unnamed".');
        $subject = new Subject();
        $subject->setMarking(['nope' => 1]);
        $workflow = new Workflow(new Definition([][])new MethodMarkingStore());

        $workflow->getMarking($subject);
    }

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

        
// check if the subject is already in the workflow         if (!$marking->getPlaces()) {
            if (!$this->definition->getInitialPlaces()) {
                throw new LogicException(sprintf('The Marking is empty and there is no initial place for workflow "%s".', $this->name));
            }
            foreach ($this->definition->getInitialPlaces() as $place) {
                $marking->mark($place);
            }

            // update the subject with the new marking             $this->markingStore->setMarking($subject$marking);

            if (!$context) {
                $context = self::DEFAULT_INITIAL_CONTEXT;
            }

            $this->entered($subject, null, $marking$context);
        }

        // check that the subject has a known place         $places = $this->definition->getPlaces();
        foreach ($marking->getPlaces() as $placeName => $nbToken) {
            

    use WorkflowBuilderTrait;

    public function testCan()
    {
        $definition = $this->createComplexStateMachineDefinition();

        $net = new StateMachine($definition);
        $subject = new Subject();

        // If you are in place "a" you should be able to apply "t1"         $subject->setMarking('a');
        $this->assertTrue($net->can($subject, 't1'));
        $subject->setMarking('d');
        $this->assertTrue($net->can($subject, 't1'));

        $subject->setMarking('b');
        $this->assertFalse($net->can($subject, 't1'));
    }

    public function testCanWithMultipleTransition()
    {
        $definition = $this->createComplexStateMachineDefinition();

        
public function testGetSetMarkingWithMultipleState()
    {
        $subject = new SubjectWithProperties();
        $markingStore = new MethodMarkingStore(false);

        $marking = $markingStore->getMarking($subject);

        $this->assertCount(0, $marking->getPlaces());

        $marking->mark('first_place');

        $markingStore->setMarking($subject$marking['foo' => 'bar']);

        $this->assertSame(['first_place' => 1]$subject->marking);

        $marking2 = $markingStore->getMarking($subject);

        $this->assertEquals($marking$marking2);
    }

    public function testGetSetMarkingWithSingleState()
    {
        $subject = new SubjectWithProperties();
        

        $subject = new Subject();

        $markingStore = new MethodMarkingStore(false);

        $marking = $markingStore->getMarking($subject);

        $this->assertCount(0, $marking->getPlaces());

        $marking->mark('first_place');

        $markingStore->setMarking($subject$marking['foo' => 'bar']);

        $this->assertSame(['first_place' => 1]$subject->getMarking());
        $this->assertSame(['foo' => 'bar']$subject->getContext());

        $marking2 = $markingStore->getMarking($subject);

        $this->assertEquals($marking$marking2);
    }

    public function testGetSetMarkingWithSingleState()
    {
        
Home | Imprint | This part of the site doesn't use cookies.