Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
9 changes: 6 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
/**
* Define a CLI command using a string expression and a callable.
*
* @param string $expression Defines the arguments and options of the command.
* @param callable|string|array $callable Called when the command is called.
* @param string $expression Defines the arguments and options of the command.
* @param callable|string|array $callable Called when the command is called.
* When using a container, this can be a "pseudo-callable"
* i.e. the name of the container entry to invoke.
*
* @param array $aliases An array of aliases for the command.
*
* @return Command
*/
public function command($expression, $callable)
public function command($expression, $callable, array $aliases = [])
{
$commandFunction = function (InputInterface $input, OutputInterface $output) use ($callable) {
$parameters = array_merge(
Expand Down Expand Up @@ -86,6 +88,7 @@ public function command($expression, $callable)
};

$command = $this->createCommand($expression, $commandFunction);
$command->setAliases($aliases);

$this->add($command);

Expand Down
11 changes: 11 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ public function runs_a_command_and_returns_exit_code()
});
$this->assertSame(1, $this->application->runCommand('foo'));
}

/**
* @test
*/
public function runs_a_command_via_its_alias_and_returns_exit_code()
{
$this->application->command('foo', function () {
return 1;
}, ['bar']);
$this->assertSame(1, $this->application->runCommand('bar'));
}
}