diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index b8c4e177ee3b9..f4787234b2a35 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -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; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 7e77903c5de4c..bd46a010b8323 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -11,9 +11,7 @@ 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; @@ -21,9 +19,8 @@ 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() { @@ -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'); @@ -87,9 +84,6 @@ public function testBootSetsTheBootedFlagToTrue() $this->assertTrue($kernel->isBooted()); } - /** - * @group legacy - */ public function testClassCacheIsLoaded() { $kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache')); @@ -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')); @@ -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'); @@ -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); @@ -253,7 +244,7 @@ public function testStripComments() $heredoc = <<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() @@ -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 */ @@ -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) - { - } -}