Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c232ecb

Browse filesBrowse files
committed
[Console][#18619] Prevent fatal error when calling Command#getHelper() without helperSet
Use Command::setHelperSet rather than Command#setHelperSet in exception msg Simplify exception message
1 parent b44abe3 commit c232ecb
Copy full SHA for c232ecb

File tree

2 files changed

+16
-1
lines changed
Filter options

2 files changed

+16
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,15 @@ public function getUsages()
601601
*
602602
* @return mixed The helper value
603603
*
604-
* @throws InvalidArgumentException if the helper is not defined
604+
* @throws LogicException If no helperSet is defined
605+
* @throws InvalidArgumentException If the helper is not defined
605606
*/
606607
public function getHelper($name)
607608
{
609+
if (null === $this->helperSet) {
610+
throw new LogicException(sprintf('Cannot retrieve helper "%s" because there is no HelperSet defined.', $name));
611+
}
612+
608613
return $this->helperSet->get($name);
609614
}
610615

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/CommandTest.php
+10Lines 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 Cannot retrieve helper "formatter" because there is no HelperSet defined.
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.