diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-19 23:45:37 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-19 23:45:37 +0900 |
| commit | 0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc (patch) | |
| tree | ba5602549ce20b8d71136423e85dffc25deafff4 /crates/shirabe/tests/command/search_command_test.rs | |
| parent | 6ed3a85dd636366d194c9810fd777db7f25e263f (diff) | |
| download | php-shirabe-0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc.tar.gz php-shirabe-0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc.tar.zst php-shirabe-0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/command/search_command_test.rs')
| -rw-r--r-- | crates/shirabe/tests/command/search_command_test.rs | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/crates/shirabe/tests/command/search_command_test.rs b/crates/shirabe/tests/command/search_command_test.rs index 7806ea0f..cc011d0f 100644 --- a/crates/shirabe/tests/command/search_command_test.rs +++ b/crates/shirabe/tests/command/search_command_test.rs @@ -2,7 +2,8 @@ use crate::test_case::{RunOptions, get_application_tester, init_temp_composer}; use serial_test::serial; -use shirabe_php_shim::PhpMixed; +use shirabe_symfony_console::input::InputValue; +use shirabe_symfony_console::input::ParameterName; fn repositories_json() -> serde_json::Value { serde_json::json!({ @@ -22,11 +23,11 @@ fn repositories_json() -> serde_json::Value { } /// ref: SearchCommandTest::testSearch (data provider rolled into one body). -fn run_search_case(command: Vec<(PhpMixed, PhpMixed)>, expected: &str) { +fn run_search_case(command: Vec<(ParameterName, InputValue)>, expected: &str) { let _tear_down = init_temp_composer(Some(&repositories_json()), None, None, true); - let mut input: Vec<(PhpMixed, PhpMixed)> = - vec![(PhpMixed::from("command"), PhpMixed::from("search"))]; + let mut input: Vec<(ParameterName, InputValue)> = + vec![(ParameterName::of("command"), InputValue::from("search"))]; input.extend(command); let mut app_tester = get_application_tester(); @@ -40,8 +41,8 @@ fn test_search() { // 'by name and description' run_search_case( vec![( - "tokens".into(), - PhpMixed::List(vec![PhpMixed::from("fancy")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["fancy".to_string()]), )], "bar/baz <warning>! Abandoned !</warning> fancy baz\nvendor-2/fancy-package", ); @@ -49,8 +50,8 @@ fn test_search() { // 'by name and description with multiple tokens' run_search_case( vec![( - "tokens".into(), - PhpMixed::List(vec![PhpMixed::from("fancy"), PhpMixed::from("vendor")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["fancy".to_string(), "vendor".to_string()]), )], "vendor-1/package-1 generic description\nbar/baz <warning>! Abandoned !</warning> fancy baz\nvendor-2/fancy-package", ); @@ -59,10 +60,10 @@ fn test_search() { run_search_case( vec![ ( - "tokens".into(), - PhpMixed::List(vec![PhpMixed::from("fancy")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["fancy".to_string()]), ), - ("--only-name".into(), PhpMixed::from(true)), + (ParameterName::of("--only-name"), InputValue::from(true)), ], "vendor-2/fancy-package", ); @@ -70,8 +71,11 @@ fn test_search() { // 'by vendor only' run_search_case( vec![ - ("tokens".into(), PhpMixed::List(vec![PhpMixed::from("bar")])), - ("--only-vendor".into(), PhpMixed::from(true)), + ( + ParameterName::of("tokens"), + InputValue::Array(vec!["bar".to_string()]), + ), + (ParameterName::of("--only-vendor"), InputValue::from(true)), ], "bar", ); @@ -80,10 +84,10 @@ fn test_search() { run_search_case( vec![ ( - "tokens".into(), - PhpMixed::List(vec![PhpMixed::from("vendor")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["vendor".to_string()]), ), - ("--type".into(), PhpMixed::from("foo")), + (ParameterName::of("--type"), InputValue::from("foo")), ], "vendor-2/fancy-package", ); @@ -92,10 +96,10 @@ fn test_search() { run_search_case( vec![ ( - "tokens".into(), - PhpMixed::List(vec![PhpMixed::from("vendor-2/fancy")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["vendor-2/fancy".to_string()]), ), - ("--format".into(), PhpMixed::from("json")), + (ParameterName::of("--format"), InputValue::from("json")), ], "[\n {\n \"name\": \"vendor-2/fancy-package\",\n \"description\": null\n }\n]", ); @@ -103,8 +107,8 @@ fn test_search() { // 'no results' run_search_case( vec![( - "tokens".into(), - PhpMixed::List(vec![PhpMixed::from("invalid-package-name")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["invalid-package-name".to_string()]), )], "", ); @@ -124,11 +128,14 @@ fn test_invalid_format() { let result = app_tester .run( vec![ - (PhpMixed::from("command"), PhpMixed::from("search")), - (PhpMixed::from("--format"), PhpMixed::from("test-format")), + (ParameterName::of("command"), InputValue::from("search")), + ( + ParameterName::of("--format"), + InputValue::from("test-format"), + ), ( - PhpMixed::from("tokens"), - PhpMixed::List(vec![PhpMixed::from("test")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["test".to_string()]), ), ], RunOptions::default(), @@ -155,12 +162,12 @@ fn test_invalid_flags() { let err = app_tester .run( vec![ - (PhpMixed::from("command"), PhpMixed::from("search")), - (PhpMixed::from("--only-vendor"), PhpMixed::from(true)), - (PhpMixed::from("--only-name"), PhpMixed::from(true)), + (ParameterName::of("command"), InputValue::from("search")), + (ParameterName::of("--only-vendor"), InputValue::from(true)), + (ParameterName::of("--only-name"), InputValue::from(true)), ( - PhpMixed::from("tokens"), - PhpMixed::List(vec![PhpMixed::from("test")]), + ParameterName::of("tokens"), + InputValue::Array(vec!["test".to_string()]), ), ], RunOptions::default(), |
