From 2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 12:40:10 +0900 Subject: 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 --- .../tests/downloader/zip_downloader_test.rs | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'crates/shirabe/tests/downloader/zip_downloader_test.rs') 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!() } }; -- cgit v1.3.1