[Console] Throw an exception if the command does not contain aliases
It can only happend if the constructor has been overridden
This commit is contained in:
parent
554d57b399
commit
7e5c9011c9
@ -407,6 +407,10 @@ class Application
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $command->getAliases()) {
|
||||
throw new \InvalidArgumentException(sprintf('You must call the parent constructor in "%s::__construct()"', get_class($command)));
|
||||
}
|
||||
|
||||
$this->commands[$command->getName()] = $command;
|
||||
|
||||
foreach ($command->getAliases() as $alias) {
|
||||
|
@ -40,6 +40,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
require_once self::$fixturesPath.'/Foo2Command.php';
|
||||
require_once self::$fixturesPath.'/Foo3Command.php';
|
||||
require_once self::$fixturesPath.'/Foo4Command.php';
|
||||
require_once self::$fixturesPath.'/Foo5Command.php';
|
||||
require_once self::$fixturesPath.'/FoobarCommand.php';
|
||||
}
|
||||
|
||||
@ -125,6 +126,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage You must call the parent constructor in "Foo5Command::__construct()"
|
||||
*/
|
||||
public function testAddCommandWithEmptyContructor()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add($foo = new \Foo5Command());
|
||||
}
|
||||
|
||||
public function testHasGet()
|
||||
{
|
||||
$application = new Application();
|
||||
|
10
src/Symfony/Component/Console/Tests/Fixtures/Foo5Command.php
Normal file
10
src/Symfony/Component/Console/Tests/Fixtures/Foo5Command.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class Foo5Command extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user