From 962e8214f21d2b6154c858aeaf1eb29f9656a2c1 Mon Sep 17 00:00:00 2001 From: madmatt Date: Wed, 19 Feb 2014 15:22:12 +1300 Subject: [PATCH] FIX: Properly extend onBeforeStartTestSession so extensions can modify the $state array --- code/TestSessionEnvironment.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/TestSessionEnvironment.php b/code/TestSessionEnvironment.php index 0fa6d9e..e5b869e 100644 --- a/code/TestSessionEnvironment.php +++ b/code/TestSessionEnvironment.php @@ -71,7 +71,15 @@ class TestSessionEnvironment extends Object { * @param array $state An array of test state options to write. */ public function startTestSession($state) { - $this->extend('onBeforeStartTestSession', $state); + $extendedState = $this->extend('onBeforeStartTestSession', $state); + + // $extendedState is now a multi-dimensional array (if extensions exist) + if($extendedState && is_array($extendedState)) { + foreach($extendedState as $stateVal) { + // $stateVal is one extension's additions to $state + $state = array_merge($state, $stateVal); // Merge this into the original $state + } + } // Convert to JSON and back so we can share the applyState() code between this and ->loadFromFile() $json = json_encode($state, JSON_FORCE_OBJECT);