8000 Deprecate the special SYMFONY__ environment variables by javiereguiluz · Pull Request #20100 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Deprecate the special SYMFONY__ environment variables #20100

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

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ protected function getEnvParameters()
$parameters = array();
foreach ($_SERVER as $key => $value) {
if (0 === strpos($key, 'SYMFONY__')) {
@trigger_error(sprintf('The support of special environment variables that start with SYMFONY__ (such as "%s") is deprecated as of 3.3 and will be removed in 4.0. Use the %env()% syntax instead to get the value of environment variables in configuration files.', $key), E_USER_DEPRECATED);
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
}
}
Expand Down
67 changes: 28 additions & 39 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
CC84
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@

namespace Symfony\Component\HttpKernel\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;

class KernelTest extends TestCase
class KernelTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
Expand Down Expand Up @@ -66,7 +63,7 @@ public function testBootInitializesBundlesAndContainer()

public function testBootSetsTheContainerToTheBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())
->method('setContainer');

Expand All @@ -87,9 +84,6 @@ public function testBootSetsTheBootedFlagToTrue()
$this->assertTrue($kernel->isBooted());
}

/**
* @group legacy
*/
public function testClassCacheIsLoaded()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
Expand All @@ -103,16 +97,13 @@ public function testClassCacheIsLoaded()

public function testClassCacheIsNotLoadedByDefault()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
$kernel->expects($this->never())
->method('doLoadClassCache');

$kernel->boot();
}

/**
* @group legacy
*/
public function testClassCacheIsNotLoadedWhenKernelIsNotBooted()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
Expand Down Expand Up @@ -169,7 +160,7 @@ public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()

public function testShutdownCallsShutdownOnAllBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())
->method('shutdown');

Expand All @@ -181,7 +172,7 @@ public function testShutdownCallsShutdownOnAllBundles()

public function testShutdownGivesNullContainerToAllBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->at(3))
->method('setContainer')
->with(null);
Expand Down Expand Up @@ -253,7 +244,7 @@ public function testStripComments()
$heredoc = <<<HD


Heredoc should not be modified {$a[1+$b]}
Heredoc should not be modified


HD;
Expand Down Expand Up @@ -289,7 +280,7 @@ public function doStuff()
$heredoc = <<<HD


Heredoc should not be modified {$a[1+$b]}
Heredoc should not be modified


HD;
Expand Down Expand Up @@ -695,18 +686,22 @@ public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
{
// does not implement TerminableInterface
$httpKernel = new TestKernel();
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')
->disableOriginalConstructor()
->getMock();

$httpKernelMock
->expects($this->never())
->method('terminate');

$kernel = $this->getKernel(array('getHttpKernel'));
$kernel->expects($this->once())
->method('getHttpKernel')
->willReturn($httpKernel);
->will($this->returnValue($httpKernelMock));

$kernel->boot();
$kernel->terminate(Request::create('/'), new Response());

$this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');

// implements TerminableInterface
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
->disableOriginalConstructor()
Expand All @@ -726,16 +721,24 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
$kernel->terminate(Request::create('/'), new Response());
}

public function testKernelWithoutBundles()
/**
* @group legacy
* @expectedDeprecation The support of special environment variables that start with SYMFONY__ (such as "SYMFONY__FOO__BAR") is deprecated as of 3.3 and will be removed in 4.0. Use the %env()% syntax instead to get the value of environment variables in configuration files.
*/
public function testSymfonyEnvironmentVariables()
{
$kernel = new KernelWithoutBundles('test', true);
$kernel->boot();
$_SERVER['SYMFONY__FOO__BAR'] = 'baz';

$this->assertTrue($kernel->getContainer()->getParameter('test_executed'));
$kernel = $this->getKernel();
$method = new \ReflectionMethod($kernel, 'getEnvParameters');
$method->setAccessible(true);

$envParameters = $method->invoke($kernel);
$this->assertSame('baz', $envParameters['foo.bar']);
}

/**
* Returns a mock for the BundleInterface.
* Returns a mock for the BundleInterface
*
* @return BundleInterface
*/
Expand Down Expand Up @@ -816,17 +819,3 @@ protected function getKernelForTest(array $methods = array())
return $kernel;
}
}

class TestKernel implements HttpKernelInterface
{
public $terminateCalled = false;

public function terminate()
{
$this->terminateCalled = true;
}

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
}
}
0