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

Skip to content

Commit 359e2d9

Browse files
Merge branch '2.7' into 2.8
* 2.7: Remove unused constant Fix passing options with defaultCommand
2 parents 4fe8889 + 8f5141d commit 359e2d9

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ public function doRun(InputInterface $input, OutputInterface $output)
192192

193193
if (!$name) {
194194
$name = $this->defaultCommand;
195-
$input = new ArrayInput(array('command' => $this->defaultCommand));
195+
$this->definition->setArguments(array_merge(
196+
$this->definition->getArguments(),
197+
array(
198+
'command' => new InputArgument('command', InputArgument::OPTIONAL, $this->definition->getArgument('command')->getDescription(), $name),
199+
)
200+
));
196201
}
197202

198203
$this->runningCommand = null;

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static function setUpBeforeClass()
3939
{
4040
self::$fixturesPath = realpath(__DIR__.'/Fixtures/');
4141
require_once self::$fixturesPath.'/FooCommand.php';
42+
require_once self::$fixturesPath.'/FooOptCommand.php';
4243
require_once self::$fixturesPath.'/Foo1Command.php';
4344
require_once self::$fixturesPath.'/Foo2Command.php';
4445
require_once self::$fixturesPath.'/Foo3Command.php';
@@ -1177,16 +1178,31 @@ public function testSetRunCustomDefaultCommand()
11771178
$application->setDefaultCommand($command->getName());
11781179

11791180
$tester = new ApplicationTester($application);
1180-
$tester->run(array());
1181-
$this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
1181+
$tester->run(array(), array('interactive' => false));
1182+
$this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
11821183

11831184
$application = new CustomDefaultCommandApplication();
11841185
$application->setAutoExit(false);
11851186

11861187
$tester = new ApplicationTester($application);
1187-
$tester->run(array());
1188+
$tester->run(array(), array('interactive' => false));
11881189

1189-
$this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
1190+
$this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
1191+
}
1192+
1193+
public function testSetRunCustomDefaultCommandWithOption()
1194+
{
1195+
$command = new \FooOptCommand();
1196+
1197+
$application = new Application();
1198+
$application->setAutoExit(false);
1199+
$application->add($command);
1200+
$application->setDefaultCommand($command->getName());
1201+
1202+
$tester = new ApplicationTester($application);
1203+
$tester->run(array('--fooopt' => 'opt'), array('interactive' => false));
1204+
1205+
$this->assertEquals('called'.PHP_EOL.'opt'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
11901206
}
11911207

11921208
/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Command\Command;
4+
use Symfony\Component\Console\Input\InputInterface;
5+
use Symfony\Component\Console\Input\InputOption;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
8+
class FooOptCommand extends Command
9+
{
10+
public $input;
11+
public $output;
12+
13+
protected function configure()
14+
{
15+
$this
16+
->setName('foo:bar')
17+
->setDescription('The foo:bar command')
18+
->setAliases(array('afoobar'))
19+
->addOption('fooopt', 'fo', InputOption::VALUE_OPTIONAL, 'fooopt description')
20+
;
21+
}
22+
23+
protected function interact(InputInterface $input, OutputInterface $output)
24+
{
25+
$output->writeln('interact called');
26+
}
27+
28+
protected function execute(InputInterface $input, OutputInterface $output)
29+
{
30+
$this->input = $input;
31+
$this->output = $output;
32+
33+
$output->writeln('called');
34+
$output->writeln($this->input->getOption('fooopt'));
35+
}
36+
}

src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Usage:
22
help [options] [--] [<command_name>]
33

44
Arguments:
5-
command The command to execute
5+
command The command to execute [default: "list"]
66
command_name The command name [default: "help"]
77

88
Options:

src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
class BCryptPasswordEncoderTest extends TestCase
2121
{
2222
const PASSWORD = 'password';
23-
const BYTES = '0123456789abcdef';
2423
const VALID_COST = '04';
2524

2625
/**

0 commit comments

Comments
 (0)