aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/event_dispatcher
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-07 07:01:50 +0900
committernsfisis <nsfisis@gmail.com>2026-08-07 07:01:50 +0900
commit759b2980e70dfb8960238f75d68bb6dddce25414 (patch)
treee37a0af6423f8ae8dd26da309b278d49d45b3451 /crates/shirabe/src/event_dispatcher
parent9a393adc0ace86cac788723b524e83c63dfc91c1 (diff)
downloadphp-shirabe-759b2980e70dfb8960238f75d68bb6dddce25414.tar.gz
php-shirabe-759b2980e70dfb8960238f75d68bb6dddce25414.tar.zst
php-shirabe-759b2980e70dfb8960238f75d68bb6dddce25414.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/event_dispatcher')
-rw-r--r--crates/shirabe/src/event_dispatcher/event_dispatcher.rs31
1 files changed, 31 insertions, 0 deletions
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<GetListenersOverride>,
+ /// 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<DispatchScriptOverride>,
}
/// 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<dyn Fn(&str, bool, &[String], &IndexMap<String, PhpMixed>) -> anyhow::Result<i64>>,
+);
+
+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<String, PhpMixed>) -> anyhow::Result<i64>,
+ >,
+ ) {
+ 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<String> {
@@ -197,6 +224,10 @@ impl EventDispatcher {
additional_args: Vec<String>,
flags: IndexMap<String, PhpMixed>,
) -> anyhow::Result<i64> {
+ 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(),