From 1a87f265853c88fec81ebcf6431e8e1bd58ce890 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 24 May 2021 19:39:07 +0200 Subject: [PATCH] [HttpKernel] Throw when HttpKernel is created and the env is empty --- src/Symfony/Component/HttpKernel/Kernel.php | 5 ++++- src/Symfony/Component/HttpKernel/Tests/KernelTest.php | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 330ca1ef85c7d..27f30ad38a863 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -87,7 +87,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl public function __construct(string $environment, bool $debug) { - $this->environment = $environment; + if (!$this->environment = $environment) { + throw new \InvalidArgumentException(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', get_debug_type($this))); + } + $this->debug = $debug; } diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index e4df69e8672f7..47a337f006680 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -55,6 +55,14 @@ public function testConstructor() $this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime()); } + public function testEmptyEnv() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', KernelForTest::class)); + + new KernelForTest('', false); + } + public function testClone() { $env = 'test_env'; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy