Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c016713

Browse files
[HttpKernel] Throw when HttpKernel is create and the env is empty
1 parent 24a1c28 commit c016713

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
8787

8888
public function __construct(string $environment, bool $debug)
8989
{
90-
$this->environment = $environment;
90+
if (!$this->environment = $environment) {
91+
throw new \InvalidArgumentException(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', get_debug_type($this)));
92+
}
93+
9194
$this->debug = $debug;
9295
}
9396

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public function testConstructor()
5555
$this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime());
5656
}
5757

58+
public function testEmptyEnv()
59+
{
60+
$this->expectException(\InvalidArgumentException::class);
61+
$this->expectExceptionMessage(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', KernelForTest::class));
62+
63+
new KernelForTest('', false);
64+
}
65+
5866
public function testClone()
5967
{
6068
$env = 'test_env';

0 commit comments

Comments
 (0)