8000 Fix $_ENV/$_SERVER precedence in test framework by fabpot · Pull Request #24686 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix $_ENV/$_SERVER precedence in test framework #24686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed $_ENV/$_SERVER precedence in test framework
  • Loading branch information
fabpot committed Oct 26, 2017
commit 6ed9919d24eda663e5e9bda720a06204f3b788e7
12 changes: 6 additions & 6 deletions src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static function getPhpUnitCliConfigArgument()
protected static function getKernelClass()
{
if (isset($_SERVER['KERNEL_CLASS']) || isset($_ENV['KERNEL_CLASS'])) {
$class = isset($_SERVER['KERNEL_CLASS']) ? $_SERVER['KERNEL_CLASS'] : $_ENV['KERNEL_CLASS'];
$class = isset($_ENV['KERNEL_CLASS']) ? $_ENV['KERNEL_CLASS'] : $_SERVER['KERNEL_CLASS'];
if (!class_exists($class)) {
throw new \RuntimeException(sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the %s::createKernel() method.', $class, static::class));
}
Expand All @@ -116,7 +116,7 @@ protected static function getKernelClass()
}

if (isset($_SERVER['KERNEL_DIR']) || isset($_ENV['KERNEL_DIR'])) {
$dir = isset($_SERVER['KERNEL_DIR']) ? $_SERVER['KERNEL_DIR'] : $_ENV['KERNEL_DIR'];
$dir = isset($_ENV['KERNEL_DIR']) ? $_ENV['KERNEL_DIR'] : $_SERVER['KERNEL_DIR'];

if (!is_dir($dir)) {
$phpUnitDir = static::getPhpUnitXmlDir();
Expand Down Expand Up @@ -176,20 +176,20 @@ protected static function createKernel(array $options = array())

if (isset($options['environment'])) {
$env = $options['environment'];
} elseif (isset($_SERVER['APP_ENV'])) {
$env = $_SERVER['APP_ENV'];
} elseif (isset($_ENV['APP_ENV'])) {
$env = $_ENV['APP_ENV'];
} elseif (isset($_SERVER['APP_ENV'])) {
$env = $_SERVER['APP_ENV'];
} else {
$env = 'test';
}

if (isset($options['debug'])) {
$debug = $options['debug'];
} elseif (isset($_SERVER['APP_DEBUG'])) {
$debug = $_SERVER['APP_DEBUG'];
} elseif (isset($_ENV['APP_DEBUG'])) {
$debug = $_ENV['APP_DEBUG'];
} elseif (isset($_SERVER['APP_DEBUG'])) {
$debug = $_SERVER['APP_DEBUG'];
} else {
$debug = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ protected function getEnv($name)
if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) {
return $this->envCache[$name];
}
if (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
return $this->envCache[$name] = $_SERVER[$name];
}
if (isset($_ENV[$name])) {
return $this->envCache[$name] = $_ENV[$name];
}
if (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
return $this->envCache[$name] = $_SERVER[$name];
}
if (false !== ($env = getenv($name)) && null !== $env) { // null is a possible value because of thread safety issues
return $this->envCache[$name] = $env;
}
Expand Down
0