aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-07 20:51:59 +0900
committernsfisis <nsfisis@gmail.com>2026-08-07 20:51:59 +0900
commitcd9e4a2b67cdea258e1daa2d9d830b7643bc19bb (patch)
treee3dd09ac9f471b3c3900f61a6e5d58d9636dab45 /crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs
parent427e059e4ffc6ce5ff130c803f9e533b7c125089 (diff)
downloadphp-shirabe-cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb.tar.gz
php-shirabe-cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb.tar.zst
php-shirabe-cd9e4a2b67cdea258e1daa2d9d830b7643bc19bb.zip
fix(autoload-generator): survive listeners that re-enter dump()
AutoloadGenerator::dump dispatches PRE_AUTOLOAD_DUMP / POST_AUTOLOAD_DUMP, and EventDispatcher::make_autoloader answers those by walking back into the Composer graph -- the local repository, the installation manager, and the generator itself. Installer::run held mutable borrows of all three across the dump call, so any plugin subscribing to either event panicked with "RefCell already borrowed" before its listener ran. dump() and build_package_map() now take the local repository, the installation manager and the locker as shared handles instead of &mut dyn, and the borrow is taken where it is used. The generator itself is re-entered, not just borrowed twice: PHP listeners reach it through Composer::getAutoloadGenerator() and call setDevMode() while dump() is running, and make_autoloader asks the same object for a package map. That is not expressible behind &mut self, so the mutable state moves into Cell/RefCell fields and the whole AutoloadGeneratorInterface takes &self. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs')
-rw-r--r--crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs
index d97c14f0..af8a33db 100644
--- a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs
+++ b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs
@@ -19,8 +19,7 @@ use shirabe::package::{
LockerInterface, PackageInterfaceHandle, RootPackageHandle, RootPackageInterfaceHandle,
};
use shirabe::repository::{
- InstalledArrayRepository, InstalledRepositoryInterface, RepositoryInterfaceHandle,
- RepositoryManagerInterface,
+ InstalledArrayRepository, RepositoryInterfaceHandle, RepositoryManagerInterface,
};
use shirabe::script::Event as ScriptEvent;
use shirabe::script::ScriptEvents;
@@ -405,30 +404,30 @@ mockall::mock! {
#[derive(Debug)]
pub AutoloadGenerator {}
impl AutoloadGeneratorInterface for AutoloadGenerator {
- fn set_dev_mode(&mut self, dev_mode: bool);
- fn set_class_map_authoritative(&mut self, class_map_authoritative: bool);
- fn set_apcu(&mut self, apcu: bool, apcu_prefix: Option<String>);
- fn set_run_scripts(&mut self, run_scripts: bool);
- fn set_dry_run(&mut self, dry_run: bool);
+ fn set_dev_mode(&self, dev_mode: bool);
+ fn set_class_map_authoritative(&self, class_map_authoritative: bool);
+ fn set_apcu(&self, apcu: bool, apcu_prefix: Option<String>);
+ fn set_run_scripts(&self, run_scripts: bool);
+ fn set_dry_run(&self, dry_run: bool);
fn set_platform_requirement_filter(
- &mut self,
+ &self,
platform_requirement_filter: std::rc::Rc<dyn PlatformRequirementFilterInterface>,
);
- fn dump<'a>(
- &mut self,
+ fn dump(
+ &self,
config: &Config,
- local_repo: &mut dyn InstalledRepositoryInterface,
+ local_repo: shirabe::repository::RepositoryInterfaceHandle,
root_package: RootPackageInterfaceHandle,
- installation_manager: &mut dyn InstallationManagerInterface,
+ installation_manager: std::rc::Rc<std::cell::RefCell<dyn InstallationManagerInterface>>,
target_dir: &str,
scan_psr_packages: bool,
suffix: Option<String>,
- locker: Option<&'a mut dyn LockerInterface>,
+ locker: Option<std::rc::Rc<std::cell::RefCell<dyn LockerInterface>>>,
strict_ambiguous: bool,
) -> anyhow::Result<ClassMap>;
fn build_package_map(
&self,
- installation_manager: &mut dyn InstallationManagerInterface,
+ installation_manager: std::rc::Rc<std::cell::RefCell<dyn InstallationManagerInterface>>,
root_package: RootPackageInterfaceHandle,
packages: Vec<PackageInterfaceHandle>,
) -> anyhow::Result<Vec<(PackageInterfaceHandle, Option<String>)>>;