Skip to content

Commit

Permalink
Merge pull request #70 from mcaskill/revert-sub-command-array-input
Browse files Browse the repository at this point in the history
Revert "Use ArrayInput instead of StringInput"
  • Loading branch information
mnapoli authored Jul 17, 2023
2 parents a0549ae + c48bfb0 commit 895b189
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Silly\Command\Command;
use Silly\Command\ExpressionParser;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\Input;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
Expand Down Expand Up @@ -169,7 +168,7 @@ public function runCommand($command, OutputInterface $output = null)

$command = $this->find($this->getCommandName($input));

return $command->run(new ArrayInput($input->getArguments()), $output ?: new NullOutput());
return $command->run($input, $output ?: new NullOutput());
}

/**
Expand Down
35 changes: 35 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ public function runs_a_command()
$this->assertSame(0, $code);
}

/**
* @test
*/
public function runs_a_command_with_arguments()
{
$this->application->command('greet [name] [--yell]', function ($name, $yell, OutputInterface $output) {
if ($name) {
$text = 'Hello, '.$name;
} else {
$text = 'Hello';
}

if ($yell) {
$text = strtoupper($text);
}

$output->write($text);
});

$output = new SpyOutput();
$code = $this->application->runCommand('greet', $output);
$this->assertSame('Hello', $output->output);
$this->assertSame(0, $code);

$output = new SpyOutput();
$code = $this->application->runCommand('greet John', $output);
$this->assertSame('Hello, John', $output->output);
$this->assertSame(0, $code);

$output = new SpyOutput();
$code = $this->application->runCommand('greet John --yell', $output);
$this->assertSame('HELLO, JOHN', $output->output);
$this->assertSame(0, $code);
}

/**
* @test
*/
Expand Down

0 comments on commit 895b189

Please sign in to comment.