10000 [Console][#18619] Prevent fatal error when calling Command#getHelper(… · symfony/symfony@6b99f20 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b99f20

Browse files
committed
[Console][#18619] Prevent fatal error when calling Command#getHelper() without helperSet
1 parent b44abe3 commit 6b99f20

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ public function getUsages()
605605
*/
606606
public function getHelper($name)
607607
{
608+
if (null === $this->helperSet) {
609+
throw new LogicException(sprintf('Unable to retrieve helper "%s" because there is no HelperSet defined for this command. Did you forget to call %s#setHelperSet()?', $name, get_class($this)));
610+
}
611+
608612
return $this->helperSet->get($name);
609613
}
610614

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ public function testGetHelper()
173173
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->getHelper() returns the correct helper');
174174
}
175175

176+
/**
177+
* @expectedException \LogicException
178+
* @expectedExceptionMessage Unable to retrieve helper "formatter" because there is no HelperSet defined for this command.
179+
*/
180+
public function testGetHelperWithoutHelperSet()
181+
{
182+
$command = new \TestCommand();
183+
$command->getHelper('formatter');
184+
}
185+
176186
public function testMergeApplicationDefinition()
177187
{
178188
$application1 = new Application();

0 commit comments

Comments
 (0)
0