Unverified Commit 8c347d75 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3517481 by mradcliffe, smustgrave: askHidden prompt fails with "Unknown...

Issue #3517481 by mradcliffe, smustgrave: askHidden prompt fails with "Unknown named parameter $default"

(cherry picked from commit b43aae5d)
parent dd94411b
Loading
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -93,11 +93,14 @@ public function collectValue(string $name, DataDefinitionInterface $definition,
    $method = $settings['method'];
    $arguments = $settings['arguments'] ?? [];

    if ($method !== 'askHidden') {
      // Most of the input-collecting methods of StyleInterface have a `default`
      // parameter.
      $arguments += [
        'default' => $default_value,
      ];
    }

    // We don't support using Symfony Console's inline validation; instead,
    // input definitions should define constraints.
    unset($arguments['validator']);
+30 −0
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Validator\Exception\ValidationFailedException;

/**
@@ -272,4 +274,32 @@ public function collectValue(string $name, DataDefinitionInterface $definition,
    RecipeRunner::processRecipe($recipe);
  }

  /**
   * Tests that the askHidden prompt forwards arguments correctly.
   */
  public function testAskHiddenPromptArgumentsForwarded(): void {
    $input = $this->createMock(InputInterface::class);
    $output = $this->createMock(OutputInterface::class);
    $io = new SymfonyStyle($input, $output);

    $recipe = $this->createRecipe(<<<YAML
name: 'Prompt askHidden Test'
input:
  foo:
    data_type: string
    description: Foo
    prompt:
      method: askHidden
    default:
      source: value
      value: bar
YAML
    );
    $collector = new ConsoleInputCollector($input, $io);
    // askHidden prompt should have an ArgumentCountError rather than a general
    // error.
    $this->expectException(\ArgumentCountError::class);
    $recipe->input->collectAll($collector);
  }

}