$fsm->setState('on'); $t->is($fsm->getState(), 'on', '->setState() changes the state'); $fsm->setState(null); $t->is($fsm->getState(), 'off', '->setState() to null sets the initial state'); try { $msg = '->setState() fails if the state does not exist.'; $fsm->setState('exploded'); $t->fail($msg); } catch (Exception $e) { $t->pass($msg); } $t->diag('->process()'); $t->is($fsm->getState(), 'off', '->getState() returns the inital state'); $t->is($fsm->process('push')->getState(), 'on', '->process() changes the state according to the transitions'); $t->is($fsm->process('smash')->getState(), 'broken', '->process() changes the state according to the transitions'); $t->is($fsm->processMany(array('replace', 'push', 'short out'))->getState(), 'burned out', '->processMany() processes multiple states'); try { $msg = '->process() fails when there is no transition defined for an input'; $fsm->process('twist'); $t->fail($msg); } catch (Exception $e) { $t->pass($msg); } $fsm->setDefaultTransition('broken'); $t->is($fsm->process('twist')->getState(), 'broken', '->process() uses the default transition if possible'); $fsm->setDefaultTransition(null); $fsm->reset(); $t->is($fsm->getState(), 'off', '->reset() resets the state'); $t->diag('exit actions'); $fsm->reset(); $exit = new CounterAction();