From 0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 19 Aug 2026 23:45:37 +0900 Subject: fix(input): thread a typed InputValue through the input layer Options and arguments were stored and passed as PhpMixed even though Symfony only ever puts a string, a bool, a list of strings or null in one. get_option already narrowed to InputOptionValue at the boundary; this widens that enum into InputValue and pushes it through InputInterface, InputOption/InputArgument defaults, the Input storage, ArgvInput/ArrayInput/StringInput/CompletionInput, Command::add_option and add_argument, and the Composer-side wrappers. Two neighbouring string|int unions get types of their own: InputDefinition::{get_argument,has_argument} take an ArgumentName, and ArrayInput keys its parameters by ParameterName. has_parameter_option and get_parameter_option take the values they look for as &[&str], which is what PHP's `(array) $values` cast produced anyway. Two behaviours change along the way. Input::set_option on a negated option now negates with PHP's loose bool cast rather than treating a non-bool as false, matching `!$value`. ArrayInput::parse now resolves an integer key to an argument position instead of looking up an argument literally named "0". Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/tests/command/init_command_test.rs | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'crates/shirabe/tests/command/init_command_test.rs') diff --git a/crates/shirabe/tests/command/init_command_test.rs b/crates/shirabe/tests/command/init_command_test.rs index ffb98fbb..02131356 100644 --- a/crates/shirabe/tests/command/init_command_test.rs +++ b/crates/shirabe/tests/command/init_command_test.rs @@ -6,6 +6,8 @@ use shirabe::command::init_command::InitCommand; use shirabe::json::JsonFile; use shirabe::util::platform::Platform; use shirabe_php_shim::{PHP_SERVER, PhpMixed}; +use shirabe_symfony_console::input::InputValue; +use shirabe_symfony_console::input::ParameterName; use tempfile::TempDir; fn set_up() { @@ -33,23 +35,28 @@ fn read_composer_json(dir: &std::path::Path) -> serde_json::Value { } /// `['command' => 'init', '--no-interaction' => true] + $arguments`. -fn non_interactive_input(arguments: Vec<(PhpMixed, PhpMixed)>) -> Vec<(PhpMixed, PhpMixed)> { +fn non_interactive_input( + arguments: Vec<(ParameterName, InputValue)>, +) -> Vec<(ParameterName, InputValue)> { let mut input = vec![ - (PhpMixed::from("command"), PhpMixed::from("init")), - (PhpMixed::from("--no-interaction"), PhpMixed::Bool(true)), + (ParameterName::of("command"), InputValue::from("init")), + ( + ParameterName::of("--no-interaction"), + InputValue::Bool(true), + ), ]; input.extend(arguments); input } -fn opt(name: &str, value: &str) -> (PhpMixed, PhpMixed) { - (PhpMixed::from(name), PhpMixed::from(value)) +fn opt(name: &str, value: &str) -> (ParameterName, InputValue) { + (ParameterName::of(name), InputValue::from(value)) } -fn opt_list(name: &str, values: &[&str]) -> (PhpMixed, PhpMixed) { +fn opt_list(name: &str, values: &[&str]) -> (ParameterName, InputValue) { ( - PhpMixed::from(name), - PhpMixed::List(values.iter().map(|v| PhpMixed::from(*v)).collect()), + ParameterName::of(name), + InputValue::Array(values.iter().map(|v| v.to_string()).collect()), ) } @@ -158,7 +165,7 @@ fn test_namespace_from_missing_package_name() { assert_eq!(None, namespace); } -fn run_data_provider() -> Vec<(serde_json::Value, Vec<(PhpMixed, PhpMixed)>)> { +fn run_data_provider() -> Vec<(serde_json::Value, Vec<(ParameterName, InputValue)>)> { vec![ // name argument ( @@ -382,7 +389,7 @@ enum InvalidExpectation { StderrMatches(&'static str), } -fn run_invalid_data_provider() -> Vec<(InvalidExpectation, Vec<(PhpMixed, PhpMixed)>)> { +fn run_invalid_data_provider() -> Vec<(InvalidExpectation, Vec<(ParameterName, InputValue)>)> { vec![ // invalid name argument ( @@ -547,7 +554,7 @@ fn test_interactive_run() { app_tester .run( - vec![(PhpMixed::from("command"), PhpMixed::from("init"))], + vec![(ParameterName::of("command"), InputValue::from("init"))], RunOptions::default(), ) .unwrap(); -- cgit v1.3.1-4-g156e