private function supports(Workflow $workflow, $className, $subject, $name) { if (!$subject instanceof $className) { return false; } if (null === $name) { return true; } return $name === $workflow->getName(); }
public function testItWorks() { $definition = $this->createSimpleWorkflowDefinition(); $object = new \stdClass(); $object->marking = null; $logger = new Logger(); $ed = new EventDispatcher(); $ed->addSubscriber(new AuditTrailListener($logger)); $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $ed); $workflow->apply($object, 't1'); $expected = array('Leaving "a" for subject of class "stdClass".', 'Transition "t1" for subject of class "stdClass".', 'Entering "b" for subject of class "stdClass".'); $this->assertSame($expected, $logger->logs); }
public function testItWorks() { $transitions = array(new Transition('t1', 'a', 'b'), new Transition('t2', 'a', 'b')); $definition = new Definition(array('a', 'b'), $transitions); $object = new \stdClass(); $object->marking = null; $logger = new Logger(); $ed = new EventDispatcher(); $ed->addSubscriber(new AuditTrailListener($logger)); $workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $ed); $workflow->apply($object, 't1'); $expected = array('Leaving "a" for subject of class "stdClass".', 'Transition "t1" for subject of class "stdClass".', 'Entering "b" for subject of class "stdClass".'); $this->assertSame($expected, $logger->logs); }
public function testGetEnabledTransitions() { $definition = $this->createComplexWorkflow(); $subject = new \stdClass(); $subject->marking = null; $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener('workflow.workflow_name.guard.t1', function (GuardEvent $event) { $event->setBlocked(true); }); $workflow = new Workflow($definition, new PropertyAccessorMarkingStore(), $eventDispatcher, 'workflow_name'); $this->assertEmpty($workflow->getEnabledTransitions($subject)); $subject->marking = array('d' => true); $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(2, $transitions); $this->assertSame('t3', $transitions['t3']->getName()); $this->assertSame('t4', $transitions['t4']->getName()); $subject->marking = array('c' => true, 'e' => true); $transitions = $workflow->getEnabledTransitions($subject); $this->assertCount(1, $transitions); $this->assertSame('t5', $transitions['t5']->getName()); }
public function __construct(Definition $definition, MarkingStoreInterface $markingStore = null, EventDispatcherInterface $dispatcher = null, $name = 'unnamed') { parent::__construct($definition, $markingStore ?: new SingleStateMarkingStore(), $dispatcher, $name); }