diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-01 03:08:13 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-01 03:08:13 +0900 |
| commit | 66723bc24f9eef827b239d3406ba41256ec6b5b8 (patch) | |
| tree | 2ee30910a17d3c1d5c6bba2b020c2ca0ff8f2669 | |
| parent | 925b2ee998a87dc20e1eced18040ea649bfed507 (diff) | |
| download | php-shirabe-66723bc24f9eef827b239d3406ba41256ec6b5b8.tar.gz php-shirabe-66723bc24f9eef827b239d3406ba41256ec6b5b8.tar.zst php-shirabe-66723bc24f9eef827b239d3406ba41256ec6b5b8.zip | |
test(application): port two doRun script-command tests
Port testNoPluginsDisablesPluginsWhenScriptCommandsExist and
testScriptCommandTakesPriorityOverAbbreviatedBuiltinCommand. Both stay
#[ignore]d because do_run panics at the script-registration todo!()
(application.rs:2461) when composer.json has scripts. Add a test-only
ApplicationHandle::__get_composer accessor so the first test's
getPluginManager assertions can be expressed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/tests/application_test.rs | 107 |
2 files changed, 117 insertions, 4 deletions
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index a3b4df7..7c527c6 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -2582,6 +2582,20 @@ impl ApplicationHandle { pub fn __base_application(&self) -> std::rc::Rc<std::cell::RefCell<dyn BaseApplication>> { self.0.clone() } + + /// For testing only: exposes the inner Application's `get_composer`, mirroring the public PHP + /// `$application->getComposer($required, $disablePlugins, $disableScripts)` so tests can inspect + /// the Composer instance created during do_run. + pub fn __get_composer( + &self, + required: bool, + disable_plugins: Option<bool>, + disable_scripts: Option<bool>, + ) -> anyhow::Result<Option<PartialComposerHandle>> { + self.0 + .borrow_mut() + .get_composer(required, disable_plugins, disable_scripts) + } } impl ApplicationHandle { diff --git a/crates/shirabe/tests/application_test.rs b/crates/shirabe/tests/application_test.rs index a513189..7ee58e4 100644 --- a/crates/shirabe/tests/application_test.rs +++ b/crates/shirabe/tests/application_test.rs @@ -5,6 +5,12 @@ // Symfony command-registry model), or a runtime define() of COMPOSER_DEV_WARNING_TIME, // remain unportable. +#[path = "common/test_case.rs"] +mod test_case; + +use serial_test::serial; +use test_case::init_temp_composer; + use shirabe::command::about_command::AboutCommand; use shirabe::command::self_update_command::SelfUpdateCommand; use shirabe::console::application::ApplicationHandle; @@ -108,20 +114,113 @@ fn test_process_isolation_works_multiple_times() { assert_eq!(0, application.do_run(input2, output2).unwrap()); } -#[ignore = "do_run's script-command registration is a todo!() pending the Symfony command-registry model"] +#[ignore = "Application::do_run registers the composer.json script as a command, a path that ends at a todo!() \ + (application.rs:2461, 'plugin: register reflection-instantiated command on Application::add'). With a \ + 'scripts' key present, do_run panics there before getComposer is reached"] #[test] +#[serial] fn test_no_plugins_disables_plugins_when_script_commands_exist() { let _tear_down = TearDown; set_up(); - todo!() + // PHP also calls setAutoExit(false)/setCatchErrors(false); both are Symfony base-Application + // methods the external-package stub does not model, and neither affects the do_run path + // exercised here (they only matter for run()/error catching), so only set_catch_exceptions + // is mirrored. + let _init = init_temp_composer( + Some(&serde_json::json!({ + "scripts": { + "my-script": "echo hello", + }, + })), + None, + None, + true, + ); + + let application = ApplicationHandle::new("Composer".to_string(), "".to_string()).unwrap(); + application.set_catch_exceptions(false); + + // Run list command with --no-plugins, this triggers script command registration which previously + // created a Composer instance with plugins enabled regardless of the --no-plugins flag + let input: Rc<RefCell<dyn InputInterface>> = Rc::new(RefCell::new( + ArrayInput::new( + vec![ + (PhpMixed::from("command"), PhpMixed::from("list")), + (PhpMixed::from("--no-plugins"), PhpMixed::from(true)), + ], + None, + ) + .unwrap(), + )); + let output: Rc<RefCell<dyn OutputInterface>> = + Rc::new(RefCell::new(BufferedOutput::new(None, false, None))); + application.do_run(input, output).unwrap(); + + let composer = application.__get_composer(false, None, None).unwrap(); + assert!( + composer.is_some(), + "Composer instance should have been created during script command registration" + ); + let composer = composer.unwrap(); + let composer = shirabe::composer::composer_full(&composer); + assert!( + composer + .get_plugin_manager() + .borrow() + .are_plugins_disabled("local"), + "Plugins should be disabled when --no-plugins is used" + ); + assert!( + composer + .get_plugin_manager() + .borrow() + .are_plugins_disabled("global"), + "Global plugins should be disabled when --no-plugins is used" + ); } -#[ignore = "do_run's script-command registration is a todo!() pending the Symfony command-registry model"] +#[ignore = "Application::do_run registers composer.json scripts as commands; that path ends at a todo!() \ + (application.rs:2461, 'plugin: register reflection-instantiated command on Application::add'). With a \ + 'scripts' key present, do_run panics there before the script command executes"] #[test] +#[serial] fn test_script_command_takes_priority_over_abbreviated_builtin_command() { let _tear_down = TearDown; set_up(); - todo!() + // PHP also calls setAutoExit(false)/setCatchErrors(false); both are Symfony base-Application + // methods the external-package stub does not model, and neither affects the do_run path + // exercised here (they only matter for run()/error catching), so only set_catch_exceptions + // is mirrored. + let _init = init_temp_composer( + Some(&serde_json::json!({ + "scripts": { + "check": "echo hello", + }, + })), + None, + None, + true, + ); + + let application = ApplicationHandle::new("Composer".to_string(), "".to_string()).unwrap(); + application.set_catch_exceptions(false); + + let app_output = Rc::new(RefCell::new(BufferedOutput::new(None, false, None))); + let input: Rc<RefCell<dyn InputInterface>> = Rc::new(RefCell::new( + ArrayInput::new( + vec![(PhpMixed::from("command"), PhpMixed::from("check"))], + None, + ) + .unwrap(), + )); + let output_trait: Rc<RefCell<dyn OutputInterface>> = app_output.clone(); + let exit_code = application.do_run(input, output_trait).unwrap(); + + assert_eq!(0, exit_code, "Script command should have run successfully"); + assert!( + app_output.borrow().fetch().contains("hello"), + "The \"check\" script should have been executed instead of the check-platform-reqs command" + ); } |
