aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/plugin/subscriber_test.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-04 04:31:51 +0900
committernsfisis <nsfisis@gmail.com>2026-08-04 05:43:26 +0900
commit3f3ad76eafcc5513000ac7526c74c2009bb390d8 (patch)
treee601fd78b4bed6add607305098bdf6257eeba7d8 /crates/shirabe/tests/plugin/subscriber_test.rs
parent695365a0ad68e4534425c64b7a6a4b6598b68ef7 (diff)
downloadphp-shirabe-3f3ad76eafcc5513000ac7526c74c2009bb390d8.tar.gz
php-shirabe-3f3ad76eafcc5513000ac7526c74c2009bb390d8.tar.zst
php-shirabe-3f3ad76eafcc5513000ac7526c74c2009bb390d8.zip
feat(plugin): remove subscribed listeners when a plugin is removed
Wire removePlugin to EventDispatcher::removeListener now that subscriber listeners carry the plugin's P-table handle: PHP's $candidate[0] === $listener identity check maps to phandle equality on Callable::PhpMethod. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/plugin/subscriber_test.rs')
-rw-r--r--crates/shirabe/tests/plugin/subscriber_test.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/shirabe/tests/plugin/subscriber_test.rs b/crates/shirabe/tests/plugin/subscriber_test.rs
index 8de3d8c2..1d6a7ece 100644
--- a/crates/shirabe/tests/plugin/subscriber_test.rs
+++ b/crates/shirabe/tests/plugin/subscriber_test.rs
@@ -94,6 +94,38 @@ fn test_subscriber_listener_returning_false_sets_return_code() {
}
#[test]
+fn test_remove_plugin_removes_its_subscribed_listeners() {
+ if !php_runtime_available() {
+ return;
+ }
+ let _worker = lock_php_worker();
+ let set_up = set_up();
+ install_subscriber_plugin(&set_up);
+
+ assert_eq!(0, dispatch(&set_up, "post-install-cmd"));
+
+ let plugin = set_up
+ .pm
+ .borrow()
+ .get_plugins()
+ .iter()
+ .find(|p| p.borrow().get_class_name() == "Subscriber\\Plugin")
+ .expect("the subscriber plugin is registered")
+ .clone();
+ set_up.pm.borrow_mut().remove_plugin(&plugin).unwrap();
+
+ // removePlugin removed the plugin's `[$subscriber, 'onPostInstall']` listener, so the
+ // second dispatch produces no further output.
+ let return_code = dispatch(&set_up, "post-install-cmd");
+
+ assert_eq!(0, return_code);
+ assert_eq!(
+ "activate subscriber-v1\nsubscriber saw post-install-cmd\n",
+ set_up.io.borrow().get_output()
+ );
+}
+
+#[test]
fn test_unrelated_event_does_not_reach_the_subscriber() {
if !php_runtime_available() {
return;