public load ( Finite\StateMachine\StateMachineInterface $stateMachine ) | ||
$stateMachine | Finite\StateMachine\StateMachineInterface |
public function testLoadWithProperties() { $sm = new StateMachine(); $this->object = new ArrayLoader(array('class' => 'Stateful1', 'states' => array('start' => array('type' => 'initial', 'properties' => array('foo' => true, 'bar' => false)), 'end' => array('type' => 'final')), 'transitions' => array('finish' => array('from' => array('middle'), 'to' => 'end', 'properties' => array('default' => 'default'), 'configure_properties' => function (OptionsResolver $optionsResolver) { $optionsResolver->setRequired('required'); }))), $this->callbackHandler); $this->object->load($sm); }
public function testLoadWithCustomStateAccessor() { $sa = $this->getMock('Finite\\State\\Accessor\\PropertyPathStateAccessor', array(), array(), 'CustomAccessor'); $sm = new StateMachine(); $sm->setStateAccessor($sa); $this->object->load($sm); $this->assertAttributeInstanceOf('CustomAccessor', 'stateAccessor', $sm); }
public function testLoadCallbacks() { $sm = $this->getMock('Finite\\StateMachine\\StateMachine'); $allTimes = function () { }; $beforeMiddleize = function () { }; $fromStartToOtherThanMiddle = function () { }; $this->object = new ArrayLoader(array('class' => 'Stateful1', 'states' => array('start' => array('type' => 'initial'), 'middle' => array(), 'end' => array('type' => 'final')), 'transitions' => array('middleize' => array('from' => 'start', 'to' => 'middle'), 'finish' => array('from' => array('middle'), 'to' => 'end')), 'callbacks' => array('before' => array(array('on' => 'middleize', 'do' => $beforeMiddleize), array('from' => 'start', 'to' => '-middle', 'do' => $fromStartToOtherThanMiddle)), 'after' => array(array('do' => $allTimes)))), $this->callbackHandler); $this->callbackHandler->expects($this->at(0))->method('addBefore')->with($sm, $beforeMiddleize, array('on' => 'middleize')); $this->callbackHandler->expects($this->at(1))->method('addBefore')->with($sm, $fromStartToOtherThanMiddle, array('from' => 'start', 'to' => '-middle')); $this->callbackHandler->expects($this->at(2))->method('addAfter')->with($sm, $allTimes, array()); $this->object->load($sm); }
public function __construct($telegram, $botan = null) { $this->telegram = $telegram; $this->botan = $botan; $this->stateMachine = new StateMachine(); $loader = new ArrayLoader(['class' => Context::class, 'states' => $this->states(), 'transitions' => $this->transitions()]); $loader->load($this->stateMachine); }
/** * Configures $stateMachine according to selected object * * @param \Illuminate\Database\Eloquent\Model $object * @throws \Finite\Exception\ObjectException */ private function setStateMachine(\Illuminate\Database\Eloquent\Model $object) { $config = array_merge(['class' => get_class($object)], $object->getFiniteConfig()); if (!$object->finiteStates->isEmpty()) { $object->setFiniteState($object->latestFiniteState); } $loader = new ArrayLoader($config); $loader->load($this->stateMachine); $this->stateMachine->setObject($object); $this->stateMachine->initialize(); }
protected function setUp() { $this->object = new \stdClass(); $this->object->finiteState = null; $this->alternativeObject = new \stdClass(); $this->alternativeObject->finiteState = null; $this->stateMachine = new StateMachine($this->object); $this->alternativeStateMachine = new StateMachine($this->alternativeObject, $this->stateMachine->getDispatcher()); $this->callbacksMock = $this->getMockBuilder('\\stdClass')->setMethods(array('afterItWasProposed', 'afterItWasProposedOrReviewed', 'afterItWasAnythingButProposed', 'onReview', 'afterItLeavesReviewed'))->getMock(); $states = array('draft' => array('type' => 'initial'), 'proposed' => array(), 'reviewed' => array(), 'published' => array('type' => 'final'), 'declined' => array('type' => 'final')); $transitions = array('propose' => array('from' => 'draft', 'to' => 'proposed'), 'return_to_draft' => array('from' => 'proposed', 'to' => 'draft'), 'review' => array('from' => 'proposed', 'to' => 'reviewed'), 'publish' => array('from' => 'reviewed', 'to' => 'published'), 'decline' => array('from' => array('proposed', 'reviewed'), 'to' => 'declined')); $loader = new ArrayLoader(array('states' => $states, 'transitions' => $transitions, 'callbacks' => array('after' => array(array('to' => 'proposed', 'do' => array($this->callbacksMock, 'afterItWasProposed')), array('to' => array('proposed', 'reviewed'), 'do' => array($this->callbacksMock, 'afterItWasProposedOrReviewed')), array('to' => array('-proposed'), 'do' => array($this->callbacksMock, 'afterItWasAnythingButProposed')), array('on' => 'review', 'do' => array($this->callbacksMock, 'onReview')), array('from' => 'reviewed', 'do' => array($this->callbacksMock, 'afterItLeavesReviewed')))))); $loader->load($this->stateMachine); $this->stateMachine->initialize(); $alternativeLoader = new ArrayLoader(array('states' => $states, 'transitions' => $transitions)); $alternativeLoader->load($this->alternativeStateMachine); $this->alternativeStateMachine->initialize(); }