aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe/src/console/application.rs7
-rw-r--r--crates/shirabe/tests/documentation_test.rs55
2 files changed, 60 insertions, 2 deletions
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index f3e4292..3e197a2 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -2577,6 +2577,13 @@ impl ApplicationHandle {
pub fn set_catch_exceptions(&self, boolean: bool) {
self.0.borrow_mut().set_catch_exceptions(boolean);
}
+
+ /// For testing only: exposes the application as a Symfony base-application handle, the way
+ /// console commands receive it via `getApplication()`, so tests can build an
+ /// `ApplicationDescription` over it.
+ pub fn __base_application(&self) -> std::rc::Rc<std::cell::RefCell<dyn BaseApplication>> {
+ self.0.clone()
+ }
}
impl ApplicationHandle {
diff --git a/crates/shirabe/tests/documentation_test.rs b/crates/shirabe/tests/documentation_test.rs
index 7c9bef1..07694d8 100644
--- a/crates/shirabe/tests/documentation_test.rs
+++ b/crates/shirabe/tests/documentation_test.rs
@@ -1,7 +1,58 @@
//! ref: composer/tests/Composer/Test/DocumentationTest.php
+use std::cell::RefCell;
+use std::rc::Rc;
+
+use shirabe::console::application::ApplicationHandle;
+use shirabe_external_packages::symfony::console::command::Command;
+use shirabe_external_packages::symfony::console::descriptor::application_description::ApplicationDescription;
+
+fn get_command_name(command: &Rc<RefCell<dyn Command>>) -> String {
+ let mut name = command.borrow().get_name().unwrap_or_default();
+ for alias in command.borrow().get_aliases() {
+ name = format!("{} / {}", name, alias);
+ }
+
+ name
+}
+
+fn provide_command_cases() -> Vec<Rc<RefCell<dyn Command>>> {
+ let application = ApplicationHandle::new("Composer".to_string(), "".to_string()).unwrap();
+ // setAutoExit(false) is the default in Shirabe. The setCatchErrors() call is guarded by
+ // method_exists() in PHP and has no Rust equivalent.
+ application.set_catch_exceptions(false);
+
+ let mut description =
+ ApplicationDescription::new(application.__base_application(), None, false);
+
+ let mut commands = Vec::new();
+ for command in description.get_commands().values() {
+ if ["about", "completion", "list"]
+ .contains(&command.borrow().get_name().as_deref().unwrap_or(""))
+ {
+ continue;
+ }
+ commands.push(command.clone());
+ }
+
+ commands
+}
+
#[test]
-#[ignore = "Application::set_auto_exit (setAutoExit) does not exist, required by provideCommandCases"]
fn test_command() {
- todo!()
+ let doc_content = std::fs::read_to_string(format!(
+ "{}/../../composer/doc/03-cli.md",
+ env!("CARGO_MANIFEST_DIR")
+ ))
+ .unwrap();
+
+ for command in provide_command_cases() {
+ assert!(
+ // TODO: test description
+ // TODO: test options
+ doc_content.contains(&format!("\n## {}\n\n", get_command_name(&command))),
+ "doc/03-cli.md does not contain a section for command \"{}\"",
+ get_command_name(&command),
+ );
+ }
}