Skip to content

Commit

Permalink
Ability to start or stop recording data (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrydallacroce authored Mar 12, 2020
1 parent 8c67f18 commit d35dee1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/StateMachine/Execution.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ trait Execution
{
public $execution;

private $recordsData = TRUE;

private function recordStateExecution($next_states)
{
if (!$this->recordsData) {
return;
}
if (json_encode($this->currentStates) != json_encode($next_states)) {
array_push($this->execution, $next_states);
array_push($this->execution, "");
Expand All @@ -17,8 +22,20 @@ private function recordStateExecution($next_states)

private function recordInputExecution($input)
{
if (!$this->recordsData) {
return;
}
$inputs = array_pop($this->execution);
$inputs .= $input;
array_push($this->execution, $inputs);
}

public function startRecording() {
$this->recordsData = TRUE;
}

public function stopRecording() {
$this->recordsData = FALSE;
}

}
9 changes: 9 additions & 0 deletions test/NonDeterministicStateMachineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ public function testBadPath()
$machine = $this->stateMachine;
\Maquina\Feeder::feed("acdd", $machine);
}

public function testStoppingAndStartingExecutionRecording()
{
$machine = $this->stateMachine;
$machine->stopRecording();
\Maquina\Feeder::feed("abd", $machine);
$machine->startRecording();
$this->assertTrue($machine->isCurrentlyAtAnEndState());
}
}

0 comments on commit d35dee1

Please sign in to comment.