Skip to content

Commit

Permalink
[Console] Fixed return value for Command::run
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Sep 24, 2012
1 parent 237629a commit c869a65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -157,7 +157,7 @@ protected function configure()
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return integer 0 if everything went fine, or an error code
* @return null|integer null or 0 if everything went fine, or an error code
*
* @throws \LogicException When this abstract method is not implemented
* @see setCode()
Expand Down Expand Up @@ -233,10 +233,12 @@ public function run(InputInterface $input, OutputInterface $output)
$input->validate();

if ($this->code) {
return call_user_func($this->code, $input, $output);
$statusCode = call_user_func($this->code, $input, $output);
} else {
$statusCode = $this->execute($input, $output);
}

return $this->execute($input, $output);
return is_numeric($statusCode) ? $statusCode : 0;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Expand Up @@ -221,6 +221,13 @@ public function testRun()
}
}

public function testRunReturnsAlwaysInteger()
{
$command = new \TestCommand();

$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
}

public function testSetCode()
{
$command = new \TestCommand();
Expand Down

0 comments on commit c869a65

Please sign in to comment.