aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 11:41:49 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 11:41:49 +0900
commit69b35b0c4d8cb583b389973b096f9dd2dee695c6 (patch)
tree7e9b994e0a4d290ff45c8ae44dd05ad56af77ea8 /crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs
parentf1dee6362f9b25e78f7e6417e957c0ca34356ecb (diff)
downloadphp-shirabe-69b35b0c4d8cb583b389973b096f9dd2dee695c6.tar.gz
php-shirabe-69b35b0c4d8cb583b389973b096f9dd2dee695c6.tar.zst
php-shirabe-69b35b0c4d8cb583b389973b096f9dd2dee695c6.zip
test(completion): port CommandCompletionTester and CompletionFunctionalTest
Adds the Symfony console test helper (Tester/CommandCompletionTester) and ports every CompletionFunctionalTest data-provider entry as an individual test. The tests reproduce the PHP environment by chdir'ing into the vendored composer/ checkout (its composer.json/lock provide the installed packages, scripts and package properties the expectations reference); the Packagist-backed entries query the live repository exactly like the PHP test does. Only `exec ` is ignored: its expectations require the dev checkout's fully installed vendor/bin, which the vendored checkout does not ship. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs b/crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs
new file mode 100644
index 00000000..35da1b9d
--- /dev/null
+++ b/crates/shirabe-external-packages/src/symfony/console/tester/command_completion_tester.rs
@@ -0,0 +1,54 @@
+//! ref: composer/vendor/symfony/console/Tester/CommandCompletionTester.php
+
+use crate::symfony::console::command::command::Command;
+use crate::symfony::console::completion::completion_input::CompletionInput;
+use crate::symfony::console::completion::completion_suggestions::CompletionSuggestions;
+
+/// Eases the testing of command completion.
+#[derive(Debug)]
+pub struct CommandCompletionTester {
+ command: std::rc::Rc<std::cell::RefCell<dyn Command>>,
+}
+
+impl CommandCompletionTester {
+ pub fn new(command: std::rc::Rc<std::cell::RefCell<dyn Command>>) -> Self {
+ Self { command }
+ }
+
+ /// Create completion suggestions from input tokens.
+ pub fn complete(&self, input: &[&str]) -> anyhow::Result<Vec<String>> {
+ let mut input: Vec<String> = input.iter().map(|s| s.to_string()).collect();
+ let current_index = input.len() as i64;
+ if input.last().map(String::as_str) == Some("") {
+ input.pop();
+ }
+ // array_unshift($input, $this->command->getName())
+ input.insert(0, self.command.borrow().get_name().unwrap_or_default());
+
+ let mut completion_input = CompletionInput::from_tokens(input, current_index)?;
+ {
+ let command_ref = self.command.borrow();
+ let definition = command_ref.get_definition();
+ completion_input.bind(&definition)?;
+ }
+ let mut suggestions = CompletionSuggestions::new();
+
+ self.command
+ .borrow()
+ .complete(&completion_input, &mut suggestions)?;
+
+ let mut result: Vec<String> = suggestions
+ .get_option_suggestions()
+ .iter()
+ .map(|option| format!("--{}", option.get_name()))
+ .collect();
+ // array_map('strval', ... $suggestions->getValueSuggestions())
+ result.extend(
+ suggestions
+ .get_value_suggestions()
+ .iter()
+ .map(|suggestion| suggestion.to_string()),
+ );
+ Ok(result)
+ }
+}