aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/repository/artifact_repository_test.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-22 23:42:07 +0900
committernsfisis <nsfisis@gmail.com>2026-06-22 23:42:07 +0900
commit5ab5f3b316798c1411ce8e6a7f5b091fda93589c (patch)
treec7669f94f5d9bd9adc07bc1aab3f14cfdec1ae5f /crates/shirabe/tests/repository/artifact_repository_test.rs
parentb291e714bc739262140323e08fe2fb9e91e00ee7 (diff)
downloadphp-shirabe-5ab5f3b316798c1411ce8e6a7f5b091fda93589c.tar.gz
php-shirabe-5ab5f3b316798c1411ce8e6a7f5b091fda93589c.tar.zst
php-shirabe-5ab5f3b316798c1411ce8e6a7f5b091fda93589c.zip
test: port previously-ignored Composer tests via __ test hatches
Re-evaluate the reason'd #[ignore] tests under the Phase D criterion: a test is unportable ONLY if the APIs/types needed to WRITE it do not exist. A test that compiles but panics at runtime (todo!() body, a regex the regex crate cannot compile) or fails at runtime (incomplete or incorrect impl behavior) is portable -- it is written in full and marked with a reason-less #[ignore]. About 120 test functions move from reason'd #[ignore] to reason-less #[ignore] (the ported-but-not-yet-passing signal). Impl crates gain only additive __ test hatches (init_command, pool, file_downloader, package handle link setters, artifact/path repository, repository manager, svn); no existing logic changes. Tests whose required APIs genuinely do not exist (mock/reflection harness, ApplicationTester, solve() discarding SolverProblemsException, a script::Event that cannot be passed as an originating event) keep their reason'd #[ignore]. cargo check -p shirabe --tests passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/repository/artifact_repository_test.rs')
-rw-r--r--crates/shirabe/tests/repository/artifact_repository_test.rs102
1 files changed, 93 insertions, 9 deletions
diff --git a/crates/shirabe/tests/repository/artifact_repository_test.rs b/crates/shirabe/tests/repository/artifact_repository_test.rs
index 14475da..765bdac 100644
--- a/crates/shirabe/tests/repository/artifact_repository_test.rs
+++ b/crates/shirabe/tests/repository/artifact_repository_test.rs
@@ -1,9 +1,12 @@
//! ref: composer/tests/Composer/Test/Repository/ArtifactRepositoryTest.php
-// ArtifactRepository::getPackages scans the fixture directory and opens each archive via
-// ZipArchive / PharData, both of which are todo!() in the php-shim.
+use std::cell::RefCell;
+use std::rc::Rc;
-use shirabe_php_shim::extension_loaded;
+use indexmap::IndexMap;
+use shirabe::io::{IOInterface, NullIO};
+use shirabe::repository::ArtifactRepository;
+use shirabe_php_shim::{PhpMixed, extension_loaded};
fn set_up() {
if !extension_loaded("zip") {
@@ -12,23 +15,104 @@ fn set_up() {
}
}
+fn artifacts_dir() -> String {
+ format!(
+ "{}/../../composer/tests/Composer/Test/Repository/Fixtures/artifacts",
+ env!("CARGO_MANIFEST_DIR")
+ )
+}
+
+fn create_repo(url: &str) -> ArtifactRepository {
+ let mut coordinates: IndexMap<String, PhpMixed> = IndexMap::new();
+ coordinates.insert("type".to_string(), PhpMixed::String("artifact".to_string()));
+ coordinates.insert("url".to_string(), PhpMixed::String(url.to_string()));
+
+ let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new()));
+ ArtifactRepository::new(coordinates, io).unwrap()
+}
+
#[test]
-#[ignore = "ArtifactRepository exposes no public get_packages(); it does not impl RepositoryInterface and initialize/scan_directory are private"]
+#[ignore]
fn test_extracts_configs_from_zip_archives() {
set_up();
- todo!()
+
+ let mut expected_packages = vec![
+ "vendor0/package0-0.0.1".to_string(),
+ "composer/composer-1.0.0-alpha6".to_string(),
+ "vendor1/package2-4.3.2".to_string(),
+ "vendor3/package1-5.4.3".to_string(),
+ "test/jsonInRoot-1.0.0".to_string(),
+ "test/jsonInRootTarFile-1.0.0".to_string(),
+ "test/jsonInFirstLevel-1.0.0".to_string(),
+ // The files not-an-artifact.zip and jsonSecondLevel are not valid
+ // artifacts and do not get detected.
+ ];
+
+ let mut repo = create_repo(&artifacts_dir());
+
+ let mut found_packages: Vec<String> = repo
+ .__get_packages()
+ .unwrap()
+ .iter()
+ .map(|package| {
+ format!(
+ "{}-{}",
+ package.get_pretty_name(),
+ package.get_pretty_version()
+ )
+ })
+ .collect();
+
+ expected_packages.sort();
+ found_packages.sort();
+
+ assert_eq!(expected_packages, found_packages);
+
+ let tar_package: Vec<_> = repo
+ .__get_packages()
+ .unwrap()
+ .into_iter()
+ .filter(|package| package.get_pretty_name() == "test/jsonInRootTarFile")
+ .collect();
+ assert_eq!(1, tar_package.len());
+ let tar_package = tar_package.into_iter().next_back().unwrap();
+ assert_eq!(Some("tar".to_string()), tar_package.get_dist_type());
}
#[test]
-#[ignore = "ArtifactRepository exposes no public get_packages(); it does not impl RepositoryInterface and initialize/scan_directory are private"]
+#[ignore]
fn test_absolute_repo_url_creates_absolute_url_packages() {
set_up();
- todo!()
+
+ let absolute_path = artifacts_dir();
+ let mut repo = create_repo(&absolute_path);
+
+ for package in repo.__get_packages().unwrap() {
+ assert_eq!(
+ package
+ .get_dist_url()
+ .unwrap_or_default()
+ .find(&absolute_path.replace('\\', "/")),
+ Some(0)
+ );
+ }
}
#[test]
-#[ignore = "ArtifactRepository exposes no public get_packages(); it does not impl RepositoryInterface and initialize/scan_directory are private"]
+#[ignore]
fn test_relative_repo_url_creates_relative_url_packages() {
set_up();
- todo!()
+
+ let relative_path = "tests/Composer/Test/Repository/Fixtures/artifacts";
+ let mut repo = create_repo(relative_path);
+
+ for package in repo.__get_packages().unwrap() {
+ assert_eq!(
+ package
+ .get_dist_url()
+ .unwrap_or_default()
+ .find(relative_path),
+ Some(0)
+ );
+ }
}