bug #24177 [FrameworkBundle] Add support to environment variables APP_ENV/DEBUG in KernelTestCase (yceruto)

This PR was merged into the 3.3 branch.

Discussion
----------

[FrameworkBundle] Add support to environment variables APP_ENV/DEBUG in KernelTestCase

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/recipes/pull/170#discussion_r138425265
| License       | MIT
| Doc PR        | -

/cc @fabpot

Commits
-------

8d56744 Add support to environment variables APP_ENV/DEBUG in KernelTestCase
This commit is contained in:
Nicolas Grekas 2017-09-13 09:26:10 +02:00
commit 3f4c47c23c

View File

@ -178,10 +178,27 @@ abstract class KernelTestCase extends TestCase
static::$class = static::getKernelClass();
}
return new static::$class(
isset($options['environment']) ? $options['environment'] : 'test',
isset($options['debug']) ? $options['debug'] : true
);
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'];
} 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'];
} else {
$debug = true;
}
return new static::$class($env, $debug);
}
/**