You are here

public function StateMachine_Test::init in State Machine 6

Same name and namespace in other branches
  1. 7.3 tests/state_machine.test \StateMachine_Test::init()
  2. 7 tests/state_machine.test \StateMachine_Test::init()
  3. 7.2 tests/state_machine.test \StateMachine_Test::init()

Called from StateMachine::__construct to initialize the states and events.

Overrides StateMachine::init

File

tests/state_machine.test, line 9

Class

StateMachine_Test

Code

public function init() {
  $this
    ->create_state('step1', array(
    'on_exit' => array(
      $this,
      'log_on_exit',
    ),
  ));
  $this
    ->create_state('step2', array(
    'on_enter' => array(
      $this,
      'log_on_enter',
    ),
  ));
  $this
    ->create_state('step3', array());
  $this
    ->create_event('goto2', array(
    'origin' => 'step1',
    'target' => 'step2',
  ));
  $this
    ->create_event('goto2_with_logs', array(
    'origin' => 'step1',
    'target' => 'step2',
    'guard' => array(
      $this,
      'log_on_guard',
    ),
    'before_transition' => array(
      $this,
      'log_before_transition',
    ),
    'after_transition' => array(
      $this,
      'log_after_transition',
    ),
  ));
  $this
    ->create_event('goto3', array(
    'origin' => array(
      'step1',
      'step2',
    ),
    'target' => 'step3',
    'guard' => FALSE,
    'onTransition' => FALSE,
  ));
  $this
    ->create_event('reset', array(
    'origin' => array(
      'step2',
      'step3',
    ),
    'target' => 'step1',
  ));
  $this
    ->create_event('dont_do_it', array(
    'origin' => array(
      'step1',
      'step2',
      'step3',
    ),
    'target' => 'step1',
    'guard' => array(
      $this,
      'guard_with_your_life',
    ),
  ));
}