aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 12:40:10 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 12:40:10 +0900
commit2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264 (patch)
treeff8bbb00238526c376f521647adc9ea9f486b84c /crates/shirabe/tests/downloader
parent4b92ecafd7634ad99aa432d58fbc1958d1f01270 (diff)
downloadphp-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.tar.gz
php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.tar.zst
php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.zip
test(tests): port setUp/tearDown as set_up/tear_down with TearDown
Port PHP setUp/tearDown across the ported integration tests using same-named set_up()/tear_down() functions and a TearDown struct whose Drop runs tear_down(). Fixture-init setUp returns its fixtures; tmpdir-style setUp/tearDown carry state in TearDown fields. Parts that depend on unported infrastructure (PHPUnit mocks, Config::merge, the PHP error handler) stay todo!() and are only wired into ignored stubs to avoid breaking live tests. Also fix shirabe-php-shim putenv to handle the no-'=' form (PHP unsets the variable), which Platform::clear_env relies on for the env-clearing tearDowns. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/downloader')
-rw-r--r--crates/shirabe/tests/downloader/download_manager_test.rs6
-rw-r--r--crates/shirabe/tests/downloader/file_downloader_test.rs6
-rw-r--r--crates/shirabe/tests/downloader/fossil_downloader_test.rs48
-rw-r--r--crates/shirabe/tests/downloader/git_downloader_test.rs44
-rw-r--r--crates/shirabe/tests/downloader/hg_downloader_test.rs48
-rw-r--r--crates/shirabe/tests/downloader/perforce_downloader_test.rs16
-rw-r--r--crates/shirabe/tests/downloader/xz_downloader_test.rs43
-rw-r--r--crates/shirabe/tests/downloader/zip_downloader_test.rs48
8 files changed, 259 insertions, 0 deletions
diff --git a/crates/shirabe/tests/downloader/download_manager_test.rs b/crates/shirabe/tests/downloader/download_manager_test.rs
index a047420..4bb0f0b 100644
--- a/crates/shirabe/tests/downloader/download_manager_test.rs
+++ b/crates/shirabe/tests/downloader/download_manager_test.rs
@@ -1,5 +1,10 @@
//! ref: composer/tests/Composer/Test/Downloader/DownloadManagerTest.php
+fn set_up() {
+ // The Filesystem and IO mocks are not ported.
+ todo!()
+}
+
// These mock IO and individual downloaders to drive DownloadManager's selection/download/
// update/remove logic; mocking is not available here.
macro_rules! stub {
@@ -7,6 +12,7 @@ macro_rules! stub {
#[test]
#[ignore = "mocks IO and individual downloaders to drive DownloadManager; mocking is not available"]
fn $name() {
+ set_up();
todo!()
}
};
diff --git a/crates/shirabe/tests/downloader/file_downloader_test.rs b/crates/shirabe/tests/downloader/file_downloader_test.rs
index 4e9cbc6..6e123e1 100644
--- a/crates/shirabe/tests/downloader/file_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/file_downloader_test.rs
@@ -1,5 +1,10 @@
//! ref: composer/tests/Composer/Test/Downloader/FileDownloaderTest.php
+fn set_up() {
+ // The HttpDownloader mock (disableOriginalConstructor) is not ported.
+ todo!()
+}
+
// These construct a FileDownloader with a mocked IO/HttpDownloader (curl_multi_init todo!())
// and a mocked Cache/Package to drive download/checksum behaviour.
macro_rules! stub {
@@ -7,6 +12,7 @@ macro_rules! stub {
#[test]
#[ignore = "mocks IO/HttpDownloader (curl_multi_init todo!()) and Cache/Package"]
fn $name() {
+ set_up();
todo!()
}
};
diff --git a/crates/shirabe/tests/downloader/fossil_downloader_test.rs b/crates/shirabe/tests/downloader/fossil_downloader_test.rs
index 89e0a9d..9c9dbe4 100644
--- a/crates/shirabe/tests/downloader/fossil_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/fossil_downloader_test.rs
@@ -1,5 +1,35 @@
//! ref: composer/tests/Composer/Test/Downloader/FossilDownloaderTest.php
+use shirabe::util::filesystem::Filesystem;
+use tempfile::TempDir;
+
+fn set_up() -> TempDir {
+ TempDir::new().unwrap()
+}
+
+fn tear_down(working_dir: &std::path::Path) {
+ if working_dir.is_dir() {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(working_dir).unwrap();
+ }
+}
+
+struct TearDown {
+ working_dir: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(working_dir: std::path::PathBuf) -> Self {
+ TearDown { working_dir }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.working_dir);
+ }
+}
+
// Every case constructs a FossilDownloader with a mocked IO/Config and a mocked
// ProcessExecutor to feed fossil command output; a real HttpDownloader reaches
// curl_multi_init (todo!()), and ProcessExecutor mocking is not available.
@@ -7,35 +37,53 @@
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_install_for_package_without_source_reference() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_install() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_updatefor_package_without_source_reference() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_update() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_remove() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_get_installation_source() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
diff --git a/crates/shirabe/tests/downloader/git_downloader_test.rs b/crates/shirabe/tests/downloader/git_downloader_test.rs
index c332b5d..ad5e305 100644
--- a/crates/shirabe/tests/downloader/git_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/git_downloader_test.rs
@@ -1,5 +1,46 @@
//! ref: composer/tests/Composer/Test/Downloader/GitDownloaderTest.php
+use shirabe::util::filesystem::Filesystem;
+use tempfile::TempDir;
+
+fn set_up() -> TempDir {
+ // skipIfNotExecutable('git')
+ let () = todo!();
+ // initGitVersion('1.0.0') resets the Composer\Util\Git static version cache via
+ // reflection; the static cache is not reachable from a test here.
+ #[allow(unreachable_code)]
+ {
+ let _fs = Filesystem::new(None);
+ TempDir::new().unwrap()
+ }
+}
+
+fn tear_down(working_dir: &std::path::Path) {
+ if working_dir.is_dir() {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(working_dir).unwrap();
+ }
+ // initGitVersion(false) resets the Composer\Util\Git static version cache via
+ // reflection; the static cache is not reachable from a test here.
+ todo!()
+}
+
+struct TearDown {
+ working_dir: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(working_dir: std::path::PathBuf) -> Self {
+ TearDown { working_dir }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.working_dir);
+ }
+}
+
// These construct a GitDownloader with a mocked IO/Config and a mocked ProcessExecutor to
// feed git command output; mocking is not available, and a real HttpDownloader reaches
// curl_multi_init (todo!()).
@@ -8,6 +49,9 @@ macro_rules! stub {
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn $name() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
};
diff --git a/crates/shirabe/tests/downloader/hg_downloader_test.rs b/crates/shirabe/tests/downloader/hg_downloader_test.rs
index 23c09f9..0bbcdf7 100644
--- a/crates/shirabe/tests/downloader/hg_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/hg_downloader_test.rs
@@ -1,5 +1,35 @@
//! ref: composer/tests/Composer/Test/Downloader/HgDownloaderTest.php
+use shirabe::util::filesystem::Filesystem;
+use tempfile::TempDir;
+
+fn set_up() -> TempDir {
+ TempDir::new().unwrap()
+}
+
+fn tear_down(working_dir: &std::path::Path) {
+ if working_dir.is_dir() {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(working_dir).unwrap();
+ }
+}
+
+struct TearDown {
+ working_dir: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(working_dir: std::path::PathBuf) -> Self {
+ TearDown { working_dir }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.working_dir);
+ }
+}
+
// Every case constructs an HgDownloader with a mocked IO/Config and a mocked
// ProcessExecutor to feed hg command output; a real HttpDownloader reaches
// curl_multi_init (todo!()), and ProcessExecutor mocking is not available.
@@ -7,35 +37,53 @@
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_download_for_package_without_source_reference() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_download() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_updatefor_package_without_source_reference() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_update() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_remove() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
#[test]
#[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"]
fn test_get_installation_source() {
+ let working_dir = set_up();
+ let _tear_down = TearDown::new(working_dir.path().to_path_buf());
+ let _ = &working_dir;
todo!()
}
diff --git a/crates/shirabe/tests/downloader/perforce_downloader_test.rs b/crates/shirabe/tests/downloader/perforce_downloader_test.rs
index 41ced48..e0f7637 100644
--- a/crates/shirabe/tests/downloader/perforce_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/perforce_downloader_test.rs
@@ -1,28 +1,44 @@
//! ref: composer/tests/Composer/Test/Downloader/PerforceDownloaderTest.php
+use tempfile::TempDir;
+
+fn set_up() -> TempDir {
+ let test_path = TempDir::new().unwrap();
+ // repoConfig/config/io/processExecutor/repository/package/downloader rely on
+ // ProcessExecutorMock and PHPUnit mocks of the repository and Package, which are not
+ // ported.
+ let () = todo!();
+ #[allow(unreachable_code)]
+ test_path
+}
+
// These mock Perforce, the repository config and a Package to drive PerforceDownloader's
// initialization and install paths; mocking is not available here.
#[test]
#[ignore = "mocks Perforce/repository/Package; mocking is not available"]
fn test_init_perforce_instantiates_a_new_perforce_object() {
+ let _test_path = set_up();
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/Package; mocking is not available"]
fn test_init_perforce_does_nothing_if_perforce_already_set() {
+ let _test_path = set_up();
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/Package; mocking is not available"]
fn test_do_install_with_tag() {
+ let _test_path = set_up();
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/Package; mocking is not available"]
fn test_do_install_with_no_tag() {
+ let _test_path = set_up();
todo!()
}
diff --git a/crates/shirabe/tests/downloader/xz_downloader_test.rs b/crates/shirabe/tests/downloader/xz_downloader_test.rs
index 9650991..d01779b 100644
--- a/crates/shirabe/tests/downloader/xz_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/xz_downloader_test.rs
@@ -1,7 +1,50 @@
//! ref: composer/tests/Composer/Test/Downloader/XzDownloaderTest.php
+use shirabe::util::Platform;
+use shirabe::util::filesystem::Filesystem;
+use tempfile::TempDir;
+
+fn set_up() -> TempDir {
+ if Platform::is_windows() {
+ // markTestSkipped('Skip test on Windows')
+ todo!()
+ }
+ if std::mem::size_of::<usize>() == 4 {
+ // markTestSkipped('Skip test on 32bit')
+ todo!()
+ }
+ TempDir::new().unwrap()
+}
+
+fn tear_down(test_dir: &std::path::Path) {
+ if Platform::is_windows() {
+ return;
+ }
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(test_dir).unwrap();
+}
+
+struct TearDown {
+ test_dir: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(test_dir: std::path::PathBuf) -> Self {
+ TearDown { test_dir }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.test_dir);
+ }
+}
+
#[test]
#[ignore = "needs a real HttpDownloader/Loop and an XzDownloader download cycle; HttpDownloader construction reaches curl_multi_init (todo!()) in the php-shim"]
fn test_error_messages() {
+ let test_dir = set_up();
+ let _tear_down = TearDown::new(test_dir.path().to_path_buf());
+ let _ = &test_dir;
todo!()
}
diff --git a/crates/shirabe/tests/downloader/zip_downloader_test.rs b/crates/shirabe/tests/downloader/zip_downloader_test.rs
index 0c8657c..aa4646c 100644
--- a/crates/shirabe/tests/downloader/zip_downloader_test.rs
+++ b/crates/shirabe/tests/downloader/zip_downloader_test.rs
@@ -1,5 +1,50 @@
//! ref: composer/tests/Composer/Test/Downloader/ZipDownloaderTest.php
+use shirabe::util::filesystem::Filesystem;
+use tempfile::TempDir;
+
+struct SetUp {
+ test_dir: TempDir,
+ filename: std::path::PathBuf,
+}
+
+fn set_up() -> SetUp {
+ let test_dir = TempDir::new().unwrap();
+ // The IO/Config/HttpDownloader/Package mocks are not ported; HttpDownloader construction
+ // additionally reaches curl_multi_init (todo!()).
+ let () = todo!();
+ #[allow(unreachable_code)]
+ {
+ let filename = test_dir.path().join("composer-test.zip");
+ std::fs::write(&filename, "zip").unwrap();
+ SetUp { test_dir, filename }
+ }
+}
+
+fn tear_down(test_dir: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(test_dir).unwrap();
+ // setPrivateProperty('hasZipArchive', null) resets a ZipDownloader static via reflection;
+ // the static is not reachable from a test here.
+ todo!()
+}
+
+struct TearDown {
+ test_dir: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(test_dir: std::path::PathBuf) -> Self {
+ TearDown { test_dir }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.test_dir);
+ }
+}
+
// These construct a ZipDownloader with a mocked IO/HttpDownloader/ProcessExecutor and rely
// on ZipArchive extraction (todo!() in the php-shim) plus mocked unzip behaviour.
macro_rules! stub {
@@ -7,6 +52,9 @@ macro_rules! stub {
#[test]
#[ignore = "mocks IO/HttpDownloader/ProcessExecutor and uses ZipArchive (todo!())"]
fn $name() {
+ let set_up = set_up();
+ let _tear_down = TearDown::new(set_up.test_dir.path().to_path_buf());
+ let _ = (&set_up.test_dir, &set_up.filename);
todo!()
}
};