diff --git a/src/Core/Environment.php b/src/Core/Environment.php index 6d5f1f34b..27d28c65a 100644 --- a/src/Core/Environment.php +++ b/src/Core/Environment.php @@ -43,7 +43,13 @@ class Environment public static function getVariables() { // Suppress return by-ref - return array_merge($GLOBALS, [ 'env' => static::$env ]); + $vars = [ 'env' => static::$env ]; + // needs to use a for loop, using `array_merge([], $GLOBALS);` left reference traces somehow + foreach ($GLOBALS as $varName => $varValue) { + $vars[$varName] = $varValue; + } + + return $vars; } /** diff --git a/tests/bootstrap/init.php b/tests/bootstrap/init.php index 8f31ca384..0eefed991 100644 --- a/tests/bootstrap/init.php +++ b/tests/bootstrap/init.php @@ -14,8 +14,8 @@ if (!defined('BASE_PATH')) { ini_set('display_errors', 1); // Asset folder -if (!file_exists(BASE_PATH . '/assets')) { - mkdir(BASE_PATH . '/assets', 02775); +if (!file_exists(ASSETS_PATH)) { + mkdir(ASSETS_PATH, 02775); } if (empty($_SERVER['HTTP_HOST'])) { diff --git a/tests/php/Core/EnvironmentTest.php b/tests/php/Core/EnvironmentTest.php index 220f47b58..ccd31e83e 100644 --- a/tests/php/Core/EnvironmentTest.php +++ b/tests/php/Core/EnvironmentTest.php @@ -53,4 +53,17 @@ class EnvironmentTest extends SapphireTest Environment::setVariables($vars); $this->assertEquals('initial', Environment::getEnv('_ENVTEST_RESTORED')); } + + public function testGetVariables() + { + $GLOBALS['test'] = 'global'; + $vars = Environment::getVariables(); + $this->assertArrayHasKey('test', $vars); + $this->assertEquals('global', $vars['test']); + $this->assertEquals('global', $GLOBALS['test']); + + $vars['test'] = 'fail'; + $this->assertEquals('fail', $vars['test']); + $this->assertEquals('global', $GLOBALS['test']); + } }