diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-28 07:09:19 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-28 07:20:32 +0900 |
| commit | f74d43409220ac209d01367bfc40dbc2c85be252 (patch) | |
| tree | b541b40d7774ae78d19f2ad3756f01ac3efca7a2 /crates/shirabe/tests | |
| parent | db166f15682e9ac254370e176b1cda439689e6e7 (diff) | |
| download | php-shirabe-f74d43409220ac209d01367bfc40dbc2c85be252.tar.gz php-shirabe-f74d43409220ac209d01367bfc40dbc2c85be252.tar.zst php-shirabe-f74d43409220ac209d01367bfc40dbc2c85be252.zip | |
test(console): port DocumentationTest::testCommand
Add __base_application accessor on ApplicationHandle so the test can
build an ApplicationDescription the way console commands do.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests')
| -rw-r--r-- | crates/shirabe/tests/documentation_test.rs | 55 |
1 files changed, 53 insertions, 2 deletions
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), + ); + } } |
