From e98823e599eb375b30037cc714710e3309d927d1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 17:21:00 +0900 Subject: test: port Composer tests unblocked by mockall, add seams Port 11 categories of previously-ignored Composer tests now reachable with the mockall crate: DownloadManager, VCS/Perforce/File downloaders, VersionSelector, PlatformRepository, Auditor, installer/FilesystemRepository, RootPackageLoader, util auth/http, commands, and Cache. Extract test seams additively on concrete structs as *Interface traits (Runtime, HhvmDetector, VersionGuesser, RepositorySet, Perforce, BinaryInstaller) plus mock-field seams (Cache, Filesystem); consumers take trait objects. Mocks are defined locally in the test crates via mockall::mock!, since automock-generated mocks are cfg(test)-gated and invisible across the integration-test boundary. dataProviders are ported in full; tests blocked by unported shims stay #[ignore] with documented reasons rather than reduced or weakened. Fix product bugs surfaced by the ports: - util/github: use the exception code, not the HTTP status, for 401/403 - advisory: serialize empty audit maps as [] to match PHP json_encode - repository/filesystem and downloader/file: fix RefCell double-borrow panics Co-Authored-By: Claude Opus 4.8 (1M context) --- .../tests/installer/library_installer_test.rs | 63 +++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'crates/shirabe/tests/installer') diff --git a/crates/shirabe/tests/installer/library_installer_test.rs b/crates/shirabe/tests/installer/library_installer_test.rs index 0796efe..42730fe 100644 --- a/crates/shirabe/tests/installer/library_installer_test.rs +++ b/crates/shirabe/tests/installer/library_installer_test.rs @@ -323,8 +323,67 @@ fn test_get_install_path_with_target_dir() { tear_down(&mut setup); } +/// Records the calls a `BinaryInstaller` double receives, standing in for the PHPUnit mock that +/// asserts `removeBinaries` is never called and `installBinaries` is called once. +#[derive(Debug, Default)] +struct BinaryInstallerCalls { + install_binaries: Vec<(shirabe::package::PackageInterfaceHandle, String, bool)>, + remove_binaries: Vec, +} + +#[derive(Debug)] +struct RecordingBinaryInstaller { + calls: Rc>, +} + +impl shirabe::installer::BinaryInstallerInterface for RecordingBinaryInstaller { + fn install_binaries( + &mut self, + package: shirabe::package::PackageInterfaceHandle, + install_path: &str, + warn_on_overwrite: bool, + ) { + self.calls.borrow_mut().install_binaries.push(( + package, + install_path.to_string(), + warn_on_overwrite, + )); + } + + fn remove_binaries(&mut self, package: shirabe::package::PackageInterfaceHandle) { + self.calls.borrow_mut().remove_binaries.push(package); + } +} + #[test] -#[ignore = "requires PHPUnit mock of BinaryInstaller (expects(never)->removeBinaries, expects(once)->installBinaries) injected via LibraryInstaller's binaryInstaller argument"] fn test_ensure_binaries_installed() { - todo!() + let mut setup = set_up(); + let calls = Rc::new(RefCell::new(BinaryInstallerCalls::default())); + let mut library = LibraryInstaller::new( + setup.io.clone(), + setup.composer.clone(), + Some("library".to_string()), + None, + None, + ); + library.__set_binary_installer(Box::new(RecordingBinaryInstaller { + calls: calls.clone(), + })); + let package = get_package("foo/bar", "1.0.0"); + let expected_path = library.get_install_path(package.clone()).unwrap(); + + library.ensure_binaries_presence(package.clone()); + + let recorded = calls.borrow(); + // PHP asserts removeBinaries is never called. + assert!(recorded.remove_binaries.is_empty()); + // PHP asserts installBinaries is called once with ($package, getInstallPath, false). + assert_eq!(recorded.install_binaries.len(), 1); + let (recorded_package, recorded_path, warn_on_overwrite) = &recorded.install_binaries[0]; + assert!(Rc::ptr_eq(recorded_package.as_rc(), package.as_rc())); + assert_eq!(recorded_path, &expected_path); + assert!(!warn_on_overwrite); + drop(recorded); + + tear_down(&mut setup); } -- cgit v1.3.1