Loading core/lib/Drupal/Core/Recipe/ConsoleInputCollector.php +6 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,12 @@ public function collectValue(string $name, DataDefinitionInterface $definition, // input definitions should define constraints. unset($arguments['validator']); // \Symfony\Component\Console\Style\StyleInterface::ask expects the default // value to be a string or NULL. Therefore, let's cast it to a string if // necessary. if (isset($arguments['default']) && !is_string($arguments['default']) && $method === 'ask') { $arguments['default'] = (string) $arguments['default']; } return $this->io->$method(...$arguments); } Loading core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ use Drupal\Core\Recipe\InputConfigurator; use Drupal\Core\Recipe\Recipe; use Drupal\Core\Recipe\RecipeRunner; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait; Loading Loading @@ -440,4 +441,26 @@ public function testFallbackValueForUndefinedEnvironmentVariable(): void { $recipe->input->collectAll($collector); } /** * Tests that the ask prompt for integer value doesn't fail with an error. */ public function testAskPromptArgumentsInteger(): void { $input = $this->createMock(InputInterface::class); $io = $this->createMock(StyleInterface::class); $io->expects($this->once()) ->method('ask') ->with('Who are you?', '123', NULL); $data_definition = DataDefinition::create('string') ->setSetting('prompt', [ 'method' => 'ask', 'arguments' => [ 'question' => 'Who are you?', ], ]); (new ConsoleInputCollector($input, $io)) ->collectValue('test.one', $data_definition, 123); } } Loading
core/lib/Drupal/Core/Recipe/ConsoleInputCollector.php +6 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,12 @@ public function collectValue(string $name, DataDefinitionInterface $definition, // input definitions should define constraints. unset($arguments['validator']); // \Symfony\Component\Console\Style\StyleInterface::ask expects the default // value to be a string or NULL. Therefore, let's cast it to a string if // necessary. if (isset($arguments['default']) && !is_string($arguments['default']) && $method === 'ask') { $arguments['default'] = (string) $arguments['default']; } return $this->io->$method(...$arguments); } Loading
core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ use Drupal\Core\Recipe\InputConfigurator; use Drupal\Core\Recipe\Recipe; use Drupal\Core\Recipe\RecipeRunner; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait; Loading Loading @@ -440,4 +441,26 @@ public function testFallbackValueForUndefinedEnvironmentVariable(): void { $recipe->input->collectAll($collector); } /** * Tests that the ask prompt for integer value doesn't fail with an error. */ public function testAskPromptArgumentsInteger(): void { $input = $this->createMock(InputInterface::class); $io = $this->createMock(StyleInterface::class); $io->expects($this->once()) ->method('ask') ->with('Who are you?', '123', NULL); $data_definition = DataDefinition::create('string') ->setSetting('prompt', [ 'method' => 'ask', 'arguments' => [ 'question' => 'Who are you?', ], ]); (new ConsoleInputCollector($input, $io)) ->collectValue('test.one', $data_definition, 123); } }