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) --- .../shirabe/tests/command/remove_command_test.rs | 139 +++++++++++---------- 1 file changed, 70 insertions(+), 69 deletions(-) (limited to 'crates/shirabe/tests/command/remove_command_test.rs') diff --git a/crates/shirabe/tests/command/remove_command_test.rs b/crates/shirabe/tests/command/remove_command_test.rs index 9139bf26..377d78c0 100644 --- a/crates/shirabe/tests/command/remove_command_test.rs +++ b/crates/shirabe/tests/command/remove_command_test.rs @@ -9,18 +9,19 @@ use serial_test::serial; use shirabe::json::JsonFile; use shirabe::package::Link; use shirabe::package::handle::PackageInterfaceHandle; -use shirabe_php_shim::PhpMixed; use shirabe_semver::constraint::{AnyConstraint, MatchAllConstraint}; +use shirabe_symfony_console::input::InputValue; +use shirabe_symfony_console::input::ParameterName; // Symfony\Component\Console\Command\Command exit codes. const SUCCESS: i32 = 0; const FAILURE: i32 = 1; const INVALID: i32 = 2; -fn input(pairs: Vec<(&str, PhpMixed)>) -> Vec<(PhpMixed, PhpMixed)> { +fn input(pairs: Vec<(&str, InputValue)>) -> Vec<(ParameterName, InputValue)> { pairs .into_iter() - .map(|(k, v)| (PhpMixed::from(k), v)) + .map(|(k, v)| (ParameterName::of(k), v)) .collect() } @@ -47,7 +48,7 @@ fn test_exception_running_with_no_remove_packages() { let mut app_tester = get_application_tester(); let err = app_tester .run( - input(vec![("command", PhpMixed::from("remove"))]), + input(vec![("command", InputValue::from("remove"))]), RunOptions::default(), ) .expect_err("expected InvalidArgumentException for missing packages argument"); @@ -68,8 +69,8 @@ fn test_exception_when_running_unused_without_lock_file() { let err = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("--unused", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("--unused", InputValue::from(true)), ]), RunOptions::default(), ) @@ -94,10 +95,10 @@ fn test_warning_when_removing_non_existent_package() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), + ("command", InputValue::from("remove")), ( "packages", - PhpMixed::List(vec![PhpMixed::from("vendor1/package1")]), + InputValue::Array(vec!["vendor1/package1".to_string()]), ), ]), RunOptions::default(), @@ -131,11 +132,11 @@ fn test_warning_when_removing_package_from_wrong_type() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--dev", PhpMixed::from(true)), - ("--no-update", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--dev", InputValue::from(true)), + ("--no-update", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -170,11 +171,11 @@ fn test_warning_when_removing_package_with_deprecated_dependencies_flag() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--update-with-dependencies", PhpMixed::from(true)), - ("--no-update", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--update-with-dependencies", InputValue::from(true)), + ("--no-update", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -238,10 +239,10 @@ fn test_message_output_when_no_unused_packages_to_remove() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("--unused", PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("--unused", InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -286,10 +287,10 @@ fn test_remove_unused_package() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("--unused", PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("--unused", InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -355,10 +356,10 @@ fn test_remove_package_by_name() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -436,11 +437,11 @@ fn test_remove_package_by_name_with_dry_run() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--dry-run", PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--dry-run", InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -522,10 +523,10 @@ fn test_remove_allowed_plugin_package_with_no_other_allowed_plugins() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -574,10 +575,10 @@ fn test_remove_allowed_plugin_package_with_other_allowed_plugins() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -629,11 +630,11 @@ fn test_remove_packages_by_vendor() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/*")])), - ("--no-install", PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/*".to_string()])), + ("--no-install", InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -709,12 +710,12 @@ fn test_remove_packages_by_vendor_with_dry_run() { app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/*")])), - ("--dry-run", PhpMixed::from(true)), - ("--no-install", PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/*".to_string()])), + ("--dry-run", InputValue::from(true)), + ("--no-install", InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -767,11 +768,11 @@ fn test_warning_when_removing_packages_by_vendor_from_wrong_type() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/*")])), - ("--dev", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), - ("--no-update", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/*".to_string()])), + ("--dev", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), + ("--no-update", InputValue::from(true)), ]), RunOptions::default(), ) @@ -813,11 +814,11 @@ fn test_package_still_present_error_when_no_install_flag_used() { let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - ("--no-install", PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + ("--no-install", InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) @@ -903,11 +904,11 @@ fn run_update_inherited_dependencies_flag_case( let status_code = app_tester .run( input(vec![ - ("command", PhpMixed::from("remove")), - ("packages", PhpMixed::List(vec![PhpMixed::from("root/req")])), - (install_flag_name, PhpMixed::from(true)), - ("--no-audit", PhpMixed::from(true)), - ("--no-interaction", PhpMixed::from(true)), + ("command", InputValue::from("remove")), + ("packages", InputValue::Array(vec!["root/req".to_string()])), + (install_flag_name, InputValue::from(true)), + ("--no-audit", InputValue::from(true)), + ("--no-interaction", InputValue::from(true)), ]), RunOptions::default(), ) -- cgit v1.3.1-4-g156e