public function testSupports() { $object = $this->getMock('Finite\\StatefulInterface', array(), array(), 'Stateful1'); $object2 = $this->getMock('Finite\\StatefulInterface', array(), array(), 'Stateful2'); $this->assertTrue($this->object->supports($object)); $this->assertFalse($this->object->supports($object2)); }
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); }
public function testSupports() { $object = $this->getMock('Finite\\StatefulInterface', array(), array(), 'Stateful1'); $object2 = $this->getMock('Finite\\StatefulInterface', array(), array(), 'Stateful2'); $this->assertTrue($this->object->supports($object)); $this->assertFalse($this->object->supports($object2)); $alternativeLoader = new ArrayLoader(array('class' => 'Stateful1', 'graph' => 'foobar')); $this->assertTrue($alternativeLoader->supports($object, 'foobar')); $this->assertFalse($alternativeLoader->supports($object)); }
/** * 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(); }