8000 feature #9186 [Console] Throw an exception if the command does not co… · ftdebugger/symfony@10a88cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 10a88cd

Browse files
committed
feature symfony#9186 [Console] Throw an exception if the command does not contain aliases (lyrixx)
This PR was merged into the master branch. Discussion ---------- [Console] Throw an exception if the command does not contain aliases | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | license? | MIT It can only happend if the constructor has been overridden Commits ------- 7e5c901 [Console] Throw an exception if the command does not contain aliases
2 parents 554d57b + 7e5c901 commit 10a88cd

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ public function add(Command $command)
407407
return;
408408
}
409409

410+
if (null === $command->getAliases()) {
411+
throw new \InvalidArgumentException(sprintf('You must call the parent constructor in "%s::__construct()"', get_class($command)));
412+
}
413+
410414
$this->commands[$command->getName()] = $command;
411415

412416
foreach ($command->getAliases() as $alias) {

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static function setUpBeforeClass()
4040
require_once self::$fixturesPath.'/Foo2Command.php';
4141
require_once self::$fixturesPath.'/Foo3Command.php';
4242
require_once self::$fixturesPath.'/Foo4Command.php';
43+
require_once self::$fixturesPath.'/Foo5Command.php';
4344
require_once self::$fixturesPath.'/FoobarCommand.php';
4445
}
4546

@@ -125,6 +126,16 @@ public function testAdd()
125126
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
126127
}
127128

129+
/**
130+
* @expectedException InvalidArgumentException
131+
* @expectedExceptionMessage You must call the parent constructor in "Foo5Command::__construct()"
132+
*/
133+
public function testAddCommandWithEmptyContructor()
134+
{
135+
$application = new Application();
136+
$application->add($foo = new \Foo5Command());
137+
}
138+
128139
public function testHasGet()
129140
{
130141
$application = new Application();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Command\Command;
4+
5+
class Foo5Command extends Command
6+
{
7+
public function __construct()
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)
0