diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 02:52:39 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 02:52:39 +0900 |
| commit | 139045e721ff04b2e07e9fdf5bf62ed2ab6b6f4d (patch) | |
| tree | b750161b402e6d9ded1a421e62d8c49f4a89e407 /crates/shirabe/tests | |
| parent | 619eea3af7b9c5352de42af124988eab76604cd4 (diff) | |
| download | php-shirabe-139045e721ff04b2e07e9fdf5bf62ed2ab6b6f4d.tar.gz php-shirabe-139045e721ff04b2e07e9fdf5bf62ed2ab6b6f4d.tar.zst php-shirabe-139045e721ff04b2e07e9fdf5bf62ed2ab6b6f4d.zip | |
test(util): port ZipTest
Zip::get_composer_json relies on ZipArchive, whose constructor is a
todo!() in the php-shim, so all cases are #[ignore] while compiling.
Reuses the existing PHP Fixtures/Zip archives.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests')
| -rw-r--r-- | crates/shirabe/tests/util/main.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/zip_test.rs | 75 |
2 files changed, 76 insertions, 0 deletions
diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs index e0ce148..7bcdc96 100644 --- a/crates/shirabe/tests/util/main.rs +++ b/crates/shirabe/tests/util/main.rs @@ -6,3 +6,4 @@ mod platform_test; mod silencer_test; mod tar_test; mod url_test; +mod zip_test; diff --git a/crates/shirabe/tests/util/zip_test.rs b/crates/shirabe/tests/util/zip_test.rs index 2d85522..07f5629 100644 --- a/crates/shirabe/tests/util/zip_test.rs +++ b/crates/shirabe/tests/util/zip_test.rs @@ -1 +1,76 @@ //! ref: composer/tests/Composer/Test/Util/ZipTest.php + +use shirabe::util::zip::Zip; + +/// Reuses the PHP fixtures under composer/tests/Composer/Test/Util/Fixtures/Zip. +fn fixture(name: &str) -> String { + format!( + "{}/../../composer/tests/Composer/Test/Util/Fixtures/Zip/{}", + env!("CARGO_MANIFEST_DIR"), + name + ) +} + +#[test] +#[ignore = "skipped in PHP whenever the zip extension is loaded, which it always is here"] +fn test_throws_exception_if_zip_extension_is_not_loaded() { + assert!(Zip::get_composer_json("").is_err()); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_returns_nullif_the_zip_is_not_found() { + let result = Zip::get_composer_json(&fixture("invalid.zip")).unwrap(); + + assert_eq!(None, result); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_returns_null_if_the_zip_is_empty() { + let result = Zip::get_composer_json(&fixture("empty.zip")).unwrap(); + + assert_eq!(None, result); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_throws_exception_if_the_zip_has_no_composer_json() { + assert!(Zip::get_composer_json(&fixture("nojson.zip")).is_err()); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_throws_exception_if_the_composer_json_is_in_a_sub_subfolder() { + assert!(Zip::get_composer_json(&fixture("subfolders.zip")).is_err()); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_returns_composer_json_in_zip_root() { + let result = Zip::get_composer_json(&fixture("root.zip")).unwrap(); + + assert_eq!(Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), result); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_returns_composer_json_in_first_folder() { + let result = Zip::get_composer_json(&fixture("folder.zip")).unwrap(); + + assert_eq!(Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), result); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_multiple_top_level_dirs_is_invalid() { + assert!(Zip::get_composer_json(&fixture("multiple.zip")).is_err()); +} + +#[test] +#[ignore = "ZipArchive::new is todo!() in the php-shim"] +fn test_returns_composer_json_from_first_subfolder() { + let result = Zip::get_composer_json(&fixture("single-sub.zip")).unwrap(); + + assert_eq!(Some("{\n \"name\": \"foo/bar\"\n}\n".to_string()), result); +} |
