mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update getVariables to return a copy of globals rather than including the reference in an array merge
This commit is contained in:
parent
e23353fe99
commit
0863bac29a
@ -43,7 +43,12 @@ class Environment
|
||||
public static function getVariables()
|
||||
{
|
||||
// Suppress return by-ref
|
||||
return array_merge($GLOBALS, [ 'env' => static::$env ]);
|
||||
$vars = [ 'env' => static::$env ];
|
||||
foreach ($GLOBALS as $varName => $varValue) {
|
||||
$vars[$varName] = $varValue;
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user