From 761de99552b74408739d0f8e71a6e06e96c23941 Mon Sep 17 00:00:00 2001 From: Jakub Sacha Date: Mon, 3 Apr 2017 07:31:13 +0200 Subject: [PATCH 1/2] Fix passing options with defaultCommand --- src/Symfony/Component/Console/Application.php | 7 +++- .../Console/Tests/ApplicationTest.php | 24 ++++++++++--- .../Console/Tests/Fixtures/FooOptCommand.php | 36 +++++++++++++++++++ .../Tests/Fixtures/application_run2.txt | 2 +- 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index bc5e9ee66c..864979a40a 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -179,7 +179,12 @@ class Application if (!$name) { $name = $this->defaultCommand; - $input = new ArrayInput(array('command' => $this->defaultCommand)); + $this->definition->setArguments(array_merge( + $this->definition->getArguments(), + array( + 'command' => new InputArgument('command', InputArgument::OPTIONAL, $this->definition->getArgument('command')->getDescription(), $name), + ) + )); } // the command name MUST be the first element of the input diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index df6d1976e7..c3ae7c928d 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -39,6 +39,7 @@ class ApplicationTest extends TestCase { self::$fixturesPath = realpath(__DIR__.'/Fixtures/'); require_once self::$fixturesPath.'/FooCommand.php'; + require_once self::$fixturesPath.'/FooOptCommand.php'; require_once self::$fixturesPath.'/Foo1Command.php'; require_once self::$fixturesPath.'/Foo2Command.php'; require_once self::$fixturesPath.'/Foo3Command.php'; @@ -1123,16 +1124,31 @@ class ApplicationTest extends TestCase $application->setDefaultCommand($command->getName()); $tester = new ApplicationTester($application); - $tester->run(array()); - $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); + $tester->run(array(), array('interactive' => false)); + $this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); $application = new CustomDefaultCommandApplication(); $application->setAutoExit(false); $tester = new ApplicationTester($application); - $tester->run(array()); + $tester->run(array(), array('interactive' => false)); - $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); + $this->assertEquals('called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); + } + + public function testSetRunCustomDefaultCommandWithOption() + { + $command = new \FooOptCommand(); + + $application = new Application(); + $application->setAutoExit(false); + $application->add($command); + $application->setDefaultCommand($command->getName()); + + $tester = new ApplicationTester($application); + $tester->run(array('--fooopt' => 'opt'), array('interactive' => false)); + + $this->assertEquals('called'.PHP_EOL.'opt'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); } /** diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php new file mode 100644 index 0000000000..9043aa483c --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php @@ -0,0 +1,36 @@ +setName('foo:bar') + ->setDescription('The foo:bar command') + ->setAliases(array('afoobar')) + ->addOption('fooopt', 'fo', InputOption::VALUE_OPTIONAL, 'fooopt description') + ; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $output->writeln('interact called'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->input = $input; + $this->output = $output; + + $output->writeln('called'); + $output->writeln($this->input->getOption('fooopt')); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt index 9a42503c6b..06ad09ad1e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt @@ -2,7 +2,7 @@ Usage: help [options] [--] [] Arguments: - command The command to execute + command The command to execute [default: "list"] command_name The command name [default: "help"] Options: From 7168d89cf2e99d75c76f5554923681bc320faed3 Mon Sep 17 00:00:00 2001 From: AbdElKader Bouadjadja Date: Fri, 28 Jul 2017 23:20:34 +0200 Subject: [PATCH 2/2] Remove unused constant --- .../Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php index b6b6ab8c80..0977d73507 100644 --- a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php @@ -20,7 +20,6 @@ use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder; class BCryptPasswordEncoderTest extends TestCase { const PASSWORD = 'password'; - const BYTES = '0123456789abcdef'; const VALID_COST = '04'; /**