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) --- .../shirabe/src/package/version/version_guesser.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'crates/shirabe/src/package/version') diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index 8e8cc32..6fba7c4 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -49,6 +49,10 @@ pub struct VersionGuesser { /// @var IOInterface|null io: Option>>, + + /// For testing only: when true, `guess_version` always returns `None`, mirroring + /// `Composer\Test\Mock\VersionGuesserMock`. `false` in production. + mock: bool, } /// PHP: @phpstan-type Version array{version, commit, pretty_version, feature_version?, feature_pretty_version?} @@ -73,6 +77,21 @@ impl VersionGuesser { process, version_parser, io, + mock: false, + } + } + + /// For testing only: builds a guesser whose `guess_version` always returns `None`, mirroring + /// `Composer\Test\Mock\VersionGuesserMock`. + pub fn __new_mock( + config: std::rc::Rc>, + process: std::rc::Rc>, + version_parser: VersionParser, + io: Option>>, + ) -> Self { + Self { + mock: true, + ..Self::new(config, process, version_parser, io) } } @@ -85,6 +104,11 @@ impl VersionGuesser { package_config: &IndexMap, path: &str, ) -> Result> { + // For testing only (ref VersionGuesserMock::guessVersion returns null). + if self.mock { + return Ok(None); + } + if !function_exists("proc_open") { return Ok(None); } -- cgit v1.3.1