aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/common
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-25 15:37:21 +0900
committernsfisis <nsfisis@gmail.com>2026-06-26 00:20:05 +0900
commit3a883e6912e642a1bcfe68336007eae018207308 (patch)
tree2750519e1bbaaf8caa493bcf1eb15efb143280d9 /crates/shirabe/tests/common
parentd4cdccb8de8758bd46a12283f8df90e020327b99 (diff)
downloadphp-shirabe-3a883e6912e642a1bcfe68336007eae018207308.tar.gz
php-shirabe-3a883e6912e642a1bcfe68336007eae018207308.tar.zst
php-shirabe-3a883e6912e642a1bcfe68336007eae018207308.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/common')
-rw-r--r--crates/shirabe/tests/common/downloader_stub.rs129
1 files changed, 129 insertions, 0 deletions
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<RefCell<Vec<DownloaderCall>>>,
+}
+
+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<RefCell<Vec<DownloaderCall>>> {
+ 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<PackageInterfaceHandle>,
+ _output: bool,
+ ) -> anyhow::Result<Option<PhpMixed>> {
+ Ok(None)
+ }
+
+ async fn prepare(
+ &mut self,
+ _type: &str,
+ _package: PackageInterfaceHandle,
+ _path: &str,
+ _prev_package: Option<PackageInterfaceHandle>,
+ ) -> anyhow::Result<Option<PhpMixed>> {
+ Ok(None)
+ }
+
+ async fn install(
+ &mut self,
+ package: PackageInterfaceHandle,
+ path: &str,
+ _output: bool,
+ ) -> anyhow::Result<Option<PhpMixed>> {
+ 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<Option<PhpMixed>> {
+ 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<Option<PhpMixed>> {
+ 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<PackageInterfaceHandle>,
+ ) -> anyhow::Result<Option<PhpMixed>> {
+ Ok(None)
+ }
+}