From d35dee15e1d74ea02e53a3befde5ca0adc31020d Mon Sep 17 00:00:00 2001 From: thierrydallacroce Date: Thu, 12 Mar 2020 15:47:46 -0700 Subject: [PATCH] Ability to start or stop recording data (#5) --- src/StateMachine/Execution.php | 17 +++++++++++++++++ test/NonDeterministicStateMachineTest.php | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/StateMachine/Execution.php b/src/StateMachine/Execution.php index 1afe3b4..e4a458b 100644 --- a/src/StateMachine/Execution.php +++ b/src/StateMachine/Execution.php @@ -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, ""); @@ -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; + } + } diff --git a/test/NonDeterministicStateMachineTest.php b/test/NonDeterministicStateMachineTest.php index ec897a8..7fadbff 100644 --- a/test/NonDeterministicStateMachineTest.php +++ b/test/NonDeterministicStateMachineTest.php @@ -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()); + } }