@@ -168,14 +168,29 @@ public function test_isTransitionAllowed_same()
168168 * @depends test_setInitState
169169 * @depends test_allowTransition
170170 * @throws TransitionException
171+ * @throws MachineException
171172 */
172173 public function test_run_automatic_transition_through_n_states_succ ()
173174 {
175+ $ this ->machine = $ this ->createPartialMock (SampleMachine::class, ['onTransition ' ]);
176+
174177 $ this ->machine ->setInitState ($ this ->x );
175178
176179 $ this ->machine ->allowTransition ($ this ->x , $ this ->y , new AlwaysTrueAssertion ());
177180 $ this ->machine ->allowTransition ($ this ->y , $ this ->z , new AlwaysTrueAssertion ());
178181
182+
183+ $ transition1 = $ this ->machine ->getTransition ($ this ->x , $ this ->y );
184+ $ transition2 = $ this ->machine ->getTransition ($ this ->y , $ this ->z );
185+
186+ $ this ->machine ->expects ($ this ->at (0 ))
187+ ->method ('onTransition ' )
188+ ->with ($ this ->equalTo ($ transition1 ));
189+
190+ $ this ->machine ->expects ($ this ->at (1 ))
191+ ->method ('onTransition ' )
192+ ->with ($ this ->equalTo ($ transition2 ));
193+
179194 $ this ->machine ->run ();
180195
181196 $ this ->assertTrue ($ this ->machine ->isMachineState ($ this ->z ));
@@ -186,14 +201,51 @@ public function test_run_automatic_transition_through_n_states_succ()
186201 * @depends test_setInitState
187202 * @depends test_allowTransition
188203 * @throws TransitionException
204+ * @throws MachineException
205+ */
206+ public function test_runOnce_automatic_transition_through_1_state_succ ()
207+ {
208+ $ this ->machine = $ this ->createPartialMock (SampleMachine::class, ['onTransition ' ]);
209+
210+ $ this ->machine ->setInitState ($ this ->x );
211+
212+ $ this ->machine ->allowTransition ($ this ->x , $ this ->y , new AlwaysTrueAssertion ());
213+ $ this ->machine ->allowTransition ($ this ->y , $ this ->z , new AlwaysTrueAssertion ());
214+
215+ $ transition = $ this ->machine ->getTransition ($ this ->x , $ this ->y );
216+
217+ $ this ->machine ->expects ($ this ->once ())
218+ ->method ('onTransition ' )
219+ ->with ($ this ->equalTo ($ transition ));
220+
221+
222+ $ this ->machine ->runOnce ();
223+
224+ $ this ->assertTrue ($ this ->machine ->isMachineState ($ this ->y ));
225+
226+ }
227+
228+ /**
229+ * @depends test_setInitState
230+ * @depends test_allowTransition
231+ * @throws TransitionException
232+ * @throws MachineException
189233 */
190234 public function test_run_automatic_transition_through_n_states_stops ()
191235 {
236+ $ this ->machine = $ this ->createPartialMock (SampleMachine::class, ['onTransition ' ]);
237+
192238 $ this ->machine ->setInitState ($ this ->x );
193239
194240 $ this ->machine ->allowTransition ($ this ->x , $ this ->y , new AlwaysTrueAssertion ());
195241 $ this ->machine ->allowTransition ($ this ->y , $ this ->z , new AlwaysFalseAssertion ());
196242
243+ $ transition1 = $ this ->machine ->getTransition ($ this ->x , $ this ->y );
244+
245+ $ this ->machine ->expects ($ this ->once ())
246+ ->method ('onTransition ' )
247+ ->with ($ this ->equalTo ($ transition1 ));
248+
197249 $ this ->machine ->run ();
198250
199251 $ this ->assertFalse ($ this ->machine ->isMachineState ($ this ->z ));
0 commit comments