8000 [2.2][Console] command's name required when added to an application by brikou · Pull Request #4104 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.2][Console] command's name required when added to an application #4104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class Command
*
* @param string $name The name of the command
*
* @throws \LogicException When the command name is empty
*
* @api
*/
public function __construct($name = null)
Expand All @@ -61,10 +59,6 @@ public function __construct($name = null)
}

$this->configure();

if (!$this->name) {
throw new \LogicException('The command name cannot be empty.');
}
}

/**
Expand All @@ -82,10 +76,16 @@ public function ignoreValidationErrors()
*
* @param Application $application An Application instance
*
* @throws \LogicException When the command name is empty
*
* @api
*/
public function setApplication(Application $application = null)
{
if (!$this->name) {
throw new \LogicException('The command name cannot be empty.');
}

$this->application = $application;
if ($application) {
$this->setHelperSet($application->getHelperSet());
Expand Down
18 changes: 11 additions & 7 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ static public function setUpBeforeClass()

public function testConstructor()
{
try {
$command = new Command();
$this->fail('__construct() throws a \LogicException if the name is null');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '__construct() throws a \LogicException if the name is null');
$this->assertEquals('The command name cannot be empty.', $e->getMessage(), 7D3B '__construct() throws a \LogicException if the name is null');
}
$command = new Command('foo:bar');
$this->assertEquals('foo:bar', $command->getName(), '__construct() takes the command name as its first argument');
}
Expand All @@ -52,6 +45,17 @@ public function testSetApplication()
$command = new \TestCommand();
$command->setApplication($application);
$this->assertEquals($application, $command->getApplication(), '->setApplication() sets the current application');

$application = new Application();
$command = new Command();

try {
$command->setApplication($application);
$this->fail('__construct() throws a \LogicException if the command name is null or empty');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->setApplication() throws a \LogicException if the command name is null or empty');
$this->assertEquals('The command name cannot be empty.', $e->getMessage(), '->setApplication() throws a \LogicException if the command name is null or empty');
}
}

public function testSetGetDefinition()
Expand Down
0