From 3a883e6912e642a1bcfe68336007eae018207308 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 25 Jun 2026 15:37:21 +0900 Subject: test: port 35 auth/installer/io/zip/bitbucket tests; implement date_create Port auth_helper (14), library_installer (8), console_io (7), zip_downloader (3), git_bitbucket_driver (3) tests. Implement date_create/strtotime for the ISO8601/ RFC3339/relative formats Composer uses (unknown input -> None, no silent guess). Fix production bugs: Question::is_assoc list-vs-assoc, auth_helper gitlab-domains list handling, LibraryInstaller RefCell double-borrow, ZipArchive::extract_to ErrorException propagation. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/tests/common/downloader_stub.rs | 129 +++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 crates/shirabe/tests/common/downloader_stub.rs (limited to 'crates/shirabe/tests/common') diff --git a/crates/shirabe/tests/common/downloader_stub.rs b/crates/shirabe/tests/common/downloader_stub.rs new file mode 100644 index 0000000..0c4432b --- /dev/null +++ b/crates/shirabe/tests/common/downloader_stub.rs @@ -0,0 +1,129 @@ +//! No-op DownloaderInterface stub for installer tests. +//! +//! PHP mocks `Composer\Downloader\DownloadManager` directly and asserts its +//! `install`/`update`/`remove` calls. The Rust DownloadManager is a concrete type +//! that dispatches to a registered DownloaderInterface, so the equivalent stub +//! lives one level down: a downloader registered under some dist type that records +//! the calls it receives and resolves to null, the same way the PHP mock returns +//! `\React\Promise\resolve(null)`. +#![allow(dead_code)] + +use std::cell::RefCell; +use std::rc::Rc; + +use shirabe::downloader::DownloaderInterface; +use shirabe::package::PackageInterfaceHandle; +use shirabe_php_shim::PhpMixed; + +/// One recorded downloader operation, capturing the package pretty-names and the +/// target path so tests can assert what the LibraryInstaller forwarded. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum DownloaderCall { + Install { + package: String, + path: String, + }, + Update { + initial: String, + target: String, + path: String, + }, + Remove { + package: String, + path: String, + }, +} + +#[derive(Debug, Default)] +pub struct DownloaderStub { + calls: Rc>>, +} + +impl DownloaderStub { + pub fn new() -> Self { + Self::default() + } + + /// Shared handle to the recorded call log, so tests can inspect it after the + /// stub has been moved into the DownloadManager. + pub fn calls(&self) -> Rc>> { + self.calls.clone() + } +} + +#[async_trait::async_trait(?Send)] +impl DownloaderInterface for DownloaderStub { + fn get_installation_source(&self) -> String { + "dist".to_string() + } + + async fn download( + &mut self, + _package: PackageInterfaceHandle, + _path: &str, + _prev_package: Option, + _output: bool, + ) -> anyhow::Result> { + Ok(None) + } + + async fn prepare( + &mut self, + _type: &str, + _package: PackageInterfaceHandle, + _path: &str, + _prev_package: Option, + ) -> anyhow::Result> { + Ok(None) + } + + async fn install( + &mut self, + package: PackageInterfaceHandle, + path: &str, + _output: bool, + ) -> anyhow::Result> { + self.calls.borrow_mut().push(DownloaderCall::Install { + package: package.get_pretty_name(), + path: path.to_string(), + }); + Ok(None) + } + + async fn update( + &mut self, + initial: PackageInterfaceHandle, + target: PackageInterfaceHandle, + path: &str, + ) -> anyhow::Result> { + self.calls.borrow_mut().push(DownloaderCall::Update { + initial: initial.get_pretty_name(), + target: target.get_pretty_name(), + path: path.to_string(), + }); + Ok(None) + } + + async fn remove( + &mut self, + package: PackageInterfaceHandle, + path: &str, + _output: bool, + ) -> anyhow::Result> { + self.calls.borrow_mut().push(DownloaderCall::Remove { + package: package.get_pretty_name(), + path: path.to_string(), + }); + Ok(None) + } + + async fn cleanup( + &mut self, + _type: &str, + _package: PackageInterfaceHandle, + _path: &str, + _prev_package: Option, + ) -> anyhow::Result> { + Ok(None) + } +} -- cgit v1.3.1