diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-27 17:21:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-27 17:26:28 +0900 |
| commit | e98823e599eb375b30037cc714710e3309d927d1 (patch) | |
| tree | e1689ec164086798fc46aa6a58d1e914cf4873b2 /crates/shirabe/src/command/archive_command.rs | |
| parent | 20f620bdd0b5764ed2e9812dc0772f907b0d6f29 (diff) | |
| download | php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.tar.gz php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.tar.zst php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command/archive_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/archive_command.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index 9aae885..d593912 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -36,6 +36,28 @@ use crate::util::r#loop::Loop; #[derive(Debug)] pub struct ArchiveCommand { base_command_data: BaseCommandData, + /// For testing only: partial-mock seam mirroring PHPUnit `onlyMethods(['initialize', 'archive'])`. + test_hooks: RefCell<ArchiveCommandTestHooks>, +} + +/// For testing only: records and stubs for the `ArchiveCommand` partial-mock seam. +#[derive(Debug, Default)] +pub struct ArchiveCommandTestHooks { + skip_initialize: bool, + archive_stub_return: Option<i64>, + archive_calls: Vec<ArchiveCallRecord>, +} + +/// For testing only: the scalar arguments captured from a stubbed `archive` call. +#[derive(Debug, Clone)] +pub struct ArchiveCallRecord { + pub package_name: Option<String>, + pub version: Option<String>, + pub format: String, + pub dest: String, + pub file_name: Option<String>, + pub ignore_filters: bool, + pub had_composer: bool, } impl Default for ArchiveCommand { @@ -50,6 +72,7 @@ impl ArchiveCommand { pub fn new() -> Self { let command = ArchiveCommand { base_command_data: BaseCommandData::new(None), + test_hooks: RefCell::new(ArchiveCommandTestHooks::default()), }; command .configure() @@ -188,12 +211,33 @@ impl Command for ArchiveCommand { input: Rc<RefCell<dyn InputInterface>>, output: Rc<RefCell<dyn OutputInterface>>, ) -> anyhow::Result<()> { + if self.test_hooks.borrow().skip_initialize { + return Ok(()); + } base_command_initialize(self, input, output) } shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data); } +impl ArchiveCommand { + /// For testing only: makes `initialize` a no-op (PHPUnit `onlyMethods(['initialize'])`). + pub fn __test_skip_initialize(&self) { + self.test_hooks.borrow_mut().skip_initialize = true; + } + + /// For testing only: stubs `archive` to record its arguments and return `return_value` + /// without running (PHPUnit `onlyMethods(['archive'])`). + pub fn __test_stub_archive(&self, return_value: i64) { + self.test_hooks.borrow_mut().archive_stub_return = Some(return_value); + } + + /// For testing only: the arguments captured from stubbed `archive` calls. + pub fn __test_archive_calls(&self) -> Vec<ArchiveCallRecord> { + self.test_hooks.borrow().archive_calls.clone() + } +} + impl BaseCommand for ArchiveCommand { fn command_data( &self, @@ -218,6 +262,23 @@ impl ArchiveCommand { ignore_filters: bool, composer: Option<&PartialComposerHandle>, ) -> Result<i64> { + let archive_stub_return = self.test_hooks.borrow().archive_stub_return; + if let Some(return_value) = archive_stub_return { + self.test_hooks + .borrow_mut() + .archive_calls + .push(ArchiveCallRecord { + package_name, + version, + format: format.to_string(), + dest: dest.to_string(), + file_name, + ignore_filters, + had_composer: composer.is_some(), + }); + return Ok(return_value); + } + let composer_guard = composer.map(crate::composer::composer_full); let mut owned_archive_manager; let composer_archive_manager; |
