From 1e72ee3ddaf581753e30b39dfc33b48d44a25ef7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 28 Jun 2026 22:22:01 +0900 Subject: test(installer): port InstallerTest unit and integration harness Port composer/tests/Composer/Test/InstallerTest.php. testInstaller (the provideInstaller cases) is fully ported and passes; the three integration tests port doTestIntegration in full (the .test fixture loader, FactoryMock, the in-process console Application with install/update commands, and the PHPUnit assertStringMatchesFormat matcher) and remain #[ignore]'d since the install pipeline is not yet executable end-to-end. Add test-only `__`-seams to the concrete types the test depends on, since their consumers (e.g. Locker takes the concrete InstallationManager) and the subclass-style mocks have no trait to mock: InstallationManager (recording mock + as_any), Factory (__create_mock), VersionGuesser, and InstalledFilesystemRepository. The production path (mock: false) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../repository/installed_filesystem_repository.rs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/shirabe/src/repository') diff --git a/crates/shirabe/src/repository/installed_filesystem_repository.rs b/crates/shirabe/src/repository/installed_filesystem_repository.rs index 3cd21eb..8ce07e4 100644 --- a/crates/shirabe/src/repository/installed_filesystem_repository.rs +++ b/crates/shirabe/src/repository/installed_filesystem_repository.rs @@ -19,6 +19,9 @@ use shirabe_semver::constraint::AnyConstraint; #[derive(Debug)] pub struct InstalledFilesystemRepository { inner: FilesystemRepository, + /// For testing only: when true, `reload` and `write` are no-ops, mirroring + /// `Composer\Test\Mock\InstalledFilesystemRepositoryMock`. `false` in production. + mock: bool, } impl InstalledFilesystemRepository { @@ -35,6 +38,21 @@ impl InstalledFilesystemRepository { root_package, filesystem, )?, + mock: false, + }) + } + + /// For testing only: builds a repository whose `reload`/`write` are no-ops, mirroring + /// `Composer\Test\Mock\InstalledFilesystemRepositoryMock`. + pub fn __new_mock( + repository_file: JsonFile, + dump_versions: bool, + root_package: Option, + filesystem: Option>>, + ) -> Result { + Ok(Self { + mock: true, + ..Self::new(repository_file, dump_versions, root_package, filesystem)? }) } @@ -59,6 +77,10 @@ impl WritableRepositoryInterface for InstalledFilesystemRepository { dev_mode: bool, installation_manager: &mut crate::installer::InstallationManager, ) -> anyhow::Result<()> { + // For testing only (ref InstalledFilesystemRepositoryMock::write is a noop). + if self.mock { + return Ok(()); + } self.inner.write(dev_mode, installation_manager) } @@ -75,6 +97,10 @@ impl WritableRepositoryInterface for InstalledFilesystemRepository { } fn reload(&mut self) -> anyhow::Result<()> { + // For testing only (ref InstalledFilesystemRepositoryMock::reload is a noop). + if self.mock { + return Ok(()); + } self.inner.reload() } -- cgit v1.3.1