getMarking example

$this->assertTrue($event->isBlocked());
    }

    private function createEvent(Transition $transition = null): GuardEvent
    {
        $subject = new Subject();
        $transition ??= new Transition('name', 'from', 'to');

        $workflow = $this->createMock(WorkflowInterface::class);

        return new GuardEvent($subjectnew Marking($subject->getMarking() ?? [])$transition$workflow);
    }

    private function configureAuthenticationChecker($isUsed$granted = true)
    {
        if (!$isUsed) {
            $this->authenticationChecker
                ->expects($this->never())
                ->method('isGranted')
            ;

            return;
        }
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, string $name = 'unnamed', array $eventsToDispatch = null)
    {
        $this->definition = $definition;
        $this->markingStore = $markingStore ?? new MethodMarkingStore();
        $this->dispatcher = $dispatcher;
        $this->name = $name;
        $this->eventsToDispatch = $eventsToDispatch;
    }

    public function getMarking(object $subject, array $context = []): Marking
    {
        $marking = $this->markingStore->getMarking($subject);

        // 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
use PHPUnit\Framework\TestCase;
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;

class PropertiesMarkingStoreTest extends TestCase
{
    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->assertTrue($this->extension->hasMarkedPlace($subject, 'ordered'));
        $this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment'));
        $this->assertFalse($this->extension->hasMarkedPlace($subject, 'processed'));
    }

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

        $this->assertSame(['ordered', 'waiting_for_payment']$this->extension->getMarkedPlaces($subject));
        $this->assertSame($subject->getMarking()$this->extension->getMarkedPlaces($subject, false));
    }

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

        $this->assertSame('workflow title', $this->extension->getMetadata($subject, 'title'));
        $this->assertSame('ordered title', $this->extension->getMetadata($subject, 'title', 'orderer'));
        $this->assertSame('t1 title', $this->extension->getMetadata($subject, 'title', $this->t1));
        $this->assertNull($this->extension->getMetadata($subject, 'not found'));
        $this->assertNull($this->extension->getMetadata($subject, 'not found', $this->t1));
    }
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
use Symfony\Component\Workflow\Tests\Subject;

class MethodMarkingStoreTest extends TestCase
{
    public function testGetSetMarkingWithMultipleState()
    {
        $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);

        
class WorkflowTest extends TestCase
{
    use WorkflowBuilderTrait;

    public function testGetMarkingWithEmptyDefinition()
    {
        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('The Marking is empty and there is no initial place for workflow "unnamed".');
        $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 getEnabledTransition(object $subject, string $transition, string $name = null): ?Transition
    {
        return $this->workflowRegistry->get($subject$name)->getEnabledTransition($subject$transition);
    }

    /** * Returns true if the place is marked. */
    public function hasMarkedPlace(object $subject, string $placeName, string $name = null): bool
    {
        return $this->workflowRegistry->get($subject$name)->getMarking($subject)->has($placeName);
    }

    /** * Returns marked places. * * @return string[]|int[] */
    public function getMarkedPlaces(object $subject, bool $placesNameOnly = true, string $name = null): array
    {
        $places = $this->workflowRegistry->get($subject$name)->getMarking($subject)->getPlaces();

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