From 759b2980e70dfb8960238f75d68bb6dddce25414 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 7 Aug 2026 07:01:50 +0900 Subject: test: port the tests left as todo!() stubs Replace the todo!() bodies with real ports. Four autoload-generator tests now run for real; the rest stay #[ignore]d, but each ignore reason now names the concrete missing symbol instead of a vague subsystem. Production additions the ports need: the deprecated AuthHelper::addAuthenticationHeader wrapper, EventDispatcher::__set_dispatch_script_override as the seam for PHPUnit onlyMethods(['dispatchScript']), and a define() stub in the shim. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/event_dispatcher/event_dispatcher.rs | 31 ++++++++++++++++++++ crates/shirabe/src/util/auth_helper.rs | 33 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'crates/shirabe/src') diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index 4aff50c9..5043610b 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -101,6 +101,10 @@ pub struct EventDispatcher { /// when set, `get_listeners` returns this closure's result verbatim instead of resolving /// registered listeners and package scripts. get_listeners_override: Option, + /// For testing only. Mirrors PHPUnit's `getMockBuilder(EventDispatcher)->onlyMethods(['dispatchScript'])`: + /// when set, `dispatch_script` returns this closure's result instead of building and + /// dispatching a script event. + dispatch_script_override: Option, } /// For testing only. Holds a closure standing in for an overridden `getListeners` method. @@ -112,6 +116,17 @@ impl std::fmt::Debug for GetListenersOverride { } } +/// For testing only. Holds a closure standing in for an overridden `dispatchScript` method. +pub struct DispatchScriptOverride( + pub Box) -> anyhow::Result>, +); + +impl std::fmt::Debug for DispatchScriptOverride { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("DispatchScriptOverride(..)") + } +} + impl EventDispatcher { pub fn new( composer: PartialComposerWeakHandle, @@ -142,6 +157,7 @@ impl EventDispatcher { previous_hash: None, previous_listeners: IndexMap::new(), get_listeners_override: None, + dispatch_script_override: None, } } @@ -155,6 +171,17 @@ impl EventDispatcher { self.get_listeners_override = Some(GetListenersOverride(callback)); } + /// For testing only. Installs a closure that overrides `dispatch_script`, mirroring PHPUnit's + /// `onlyMethods(['dispatchScript'])->willReturnCallback(...)`. + pub fn __set_dispatch_script_override( + &mut self, + callback: Box< + dyn Fn(&str, bool, &[String], &IndexMap) -> anyhow::Result, + >, + ) { + self.dispatch_script_override = Some(DispatchScriptOverride(callback)); + } + /// For testing only. Exposes the protected `getPhpExecCommand`, mirroring the PHP tests' /// `new \ReflectionMethod($dispatcher, 'getPhpExecCommand')`. pub fn __get_php_exec_command(&self) -> anyhow::Result { @@ -197,6 +224,10 @@ impl EventDispatcher { additional_args: Vec, flags: IndexMap, ) -> anyhow::Result { + if let Some(over) = &self.dispatch_script_override { + return (over.0)(event_name, dev_mode, &additional_args, &flags); + } + let composer = self.composer(); assert!( composer.is_full(), diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index c779a1bb..a323c37e 100644 --- a/crates/shirabe/src/util/auth_helper.rs +++ b/crates/shirabe/src/util/auth_helper.rs @@ -436,6 +436,39 @@ impl AuthHelper { }) } + /// @param string[] $headers + /// + /// @return string[] updated headers array + pub fn add_authentication_header( + &mut self, + headers: Vec, + origin: &str, + url: &str, + ) -> anyhow::Result> { + shirabe_php_shim::trigger_error( + "AuthHelper::addAuthenticationHeader is deprecated since Composer 2.9 use addAuthenticationOptions instead.", + shirabe_php_shim::E_USER_DEPRECATED, + ); + + let mut http: IndexMap = IndexMap::new(); + http.insert( + "header".to_string(), + PhpMixed::List(headers.into_iter().map(PhpMixed::String).collect()), + ); + let mut options: IndexMap = IndexMap::new(); + options.insert("http".to_string(), PhpMixed::Array(http)); + let options = self.add_authentication_options(options, origin, url)?; + + Ok(options["http"] + .as_array() + .and_then(|http| http.get("header")) + .and_then(|header| header.as_list()) + .expect("addAuthenticationOptions always leaves http.header a list") + .iter() + .map(|v| v.as_string().unwrap_or("").to_string()) + .collect()) + } + /// @return array updated options pub fn add_authentication_options( &mut self, -- cgit v1.3.1