diff --git a/features/interactive.feature b/features/interactive.feature index 0fd5a4a..688f2ec 100644 --- a/features/interactive.feature +++ b/features/interactive.feature @@ -300,3 +300,19 @@ Feature: It is possible to interactively fill in a form from the CLI ) ) """ + + Scenario: Command with default form data + When I run the command "form:default_value_command" and I provide as input + | Input | + | foo | + And the output should contain + """ + Street [already save address]: + """ + And the output should contain + """ + Array + ( + [street] => foo + ) + """ diff --git a/src/Console/Command/FormBasedCommandWithDefault.php b/src/Console/Command/FormBasedCommandWithDefault.php new file mode 100644 index 0000000..ab9a351 --- /dev/null +++ b/src/Console/Command/FormBasedCommandWithDefault.php @@ -0,0 +1,13 @@ +getInput(); $output = $event->getOutput(); + $defaultData = null; + if ($command instanceof FormBasedCommandWithDefault) { + $defaultData = $command->getFormDefault(); + } - $formData = $this->formQuestionHelper->interactUsingForm($command->formType(), $input, $output); + $formData = $this->formQuestionHelper->interactUsingForm( + $command->formType(), + $input, + $output, + [], + $defaultData + ); $command->setFormData($formData); } diff --git a/test/Command/DefaultFormDataCommand.php b/test/Command/DefaultFormDataCommand.php new file mode 100644 index 0000000..18220a6 --- /dev/null +++ b/test/Command/DefaultFormDataCommand.php @@ -0,0 +1,14 @@ +setDefaults( [ - 'data_class' => 'Matthias\SymfonyConsoleForm\Tests\Form\Data\Address', + 'data_class' => Address::class, ] ); } diff --git a/test/config.yml b/test/config.yml index 931c697..264324b 100644 --- a/test/config.yml +++ b/test/config.yml @@ -26,6 +26,14 @@ services: tags: - { name: console.command } + default_value_command: + class: Matthias\SymfonyConsoleForm\Tests\Command\DefaultFormDataCommand + arguments: + - Matthias\SymfonyConsoleForm\Tests\Form\AddressType + - default_value_command + tags: + - { name: console.command } + blocked_addresses_command: class: Matthias\SymfonyConsoleForm\Tests\Command\PrintFormDataCommand arguments: diff --git a/test/console.php b/test/console.php index 9819005..d071a39 100644 --- a/test/console.php +++ b/test/console.php @@ -4,7 +4,7 @@ use Matthias\SymfonyConsoleForm\Tests\AppKernel; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Debug\Debug; +use Symfony\Component\ErrorHandler\Debug; Debug::enable();