aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 01:03:47 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 01:03:47 +0900
commitf50020461ec2ca005f11538e944e456b5a37c681 (patch)
tree31ff92ca8fb56e97b96c3702d0dd72a979ba2a20 /crates/shirabe
parentd74a67a17e05277e912caa534c74d34d9f9fc30d (diff)
downloadphp-shirabe-f50020461ec2ca005f11538e944e456b5a37c681.tar.gz
php-shirabe-f50020461ec2ca005f11538e944e456b5a37c681.tar.zst
php-shirabe-f50020461ec2ca005f11538e944e456b5a37c681.zip
test(util): port ConfigValidatorTest
Reuses the existing PHP Fixtures composer_*.json. All four cases are marked #[ignore] because ConfigValidator::validate reaches a todo!() in the php-shim. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/tests/util/config_validator_test.rs74
-rw-r--r--crates/shirabe/tests/util/main.rs1
2 files changed, 75 insertions, 0 deletions
diff --git a/crates/shirabe/tests/util/config_validator_test.rs b/crates/shirabe/tests/util/config_validator_test.rs
index 8aa46a7..dc39d66 100644
--- a/crates/shirabe/tests/util/config_validator_test.rs
+++ b/crates/shirabe/tests/util/config_validator_test.rs
@@ -1 +1,75 @@
//! ref: composer/tests/Composer/Test/Util/ConfigValidatorTest.php
+
+use std::cell::RefCell;
+use std::rc::Rc;
+
+use shirabe::io::io_interface::IOInterface;
+use shirabe::io::null_io::NullIO;
+use shirabe::package::loader::validating_array_loader::ValidatingArrayLoader;
+use shirabe::util::config_validator::ConfigValidator;
+
+fn fixture(name: &str) -> String {
+ format!(
+ "{}/../../composer/tests/Composer/Test/Util/Fixtures/{}",
+ env!("CARGO_MANIFEST_DIR"),
+ name
+ )
+}
+
+fn validate(file: &str) -> Vec<String> {
+ let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new()));
+ let config_validator = ConfigValidator::new(io);
+ let (_, _, warnings) = config_validator.validate(
+ file,
+ ValidatingArrayLoader::CHECK_ALL,
+ ConfigValidator::CHECK_VERSION,
+ );
+ warnings
+}
+
+/// Test ConfigValidator warns on commit reference
+#[test]
+#[ignore = "ConfigValidator::validate reaches a todo!() in the php-shim"]
+fn test_config_validator_commit_ref_warning() {
+ let warnings = validate(&fixture("composer_commit-ref.json"));
+
+ assert!(warnings.contains(
+ &"The package \"some/package\" is pointing to a commit-ref, this is bad practice and can cause unforeseen issues.".to_string()
+ ));
+}
+
+#[test]
+#[ignore = "ConfigValidator::validate reaches a todo!() in the php-shim"]
+fn test_config_validator_warns_on_script_description_for_nonexistent_script() {
+ let warnings = validate(&fixture("composer_scripts-descriptions.json"));
+
+ assert!(warnings.contains(
+ &"Description for non-existent script \"phpcsxxx\" found in \"scripts-descriptions\"".to_string()
+ ));
+}
+
+#[test]
+#[ignore = "ConfigValidator::validate reaches a todo!() in the php-shim"]
+fn test_config_validator_warns_on_script_alias_for_nonexistent_script() {
+ let warnings = validate(&fixture("composer_scripts-aliases.json"));
+
+ assert!(warnings.contains(
+ &"Aliases for non-existent script \"phpcsxxx\" found in \"scripts-aliases\"".to_string()
+ ));
+}
+
+#[test]
+#[ignore = "ConfigValidator::validate reaches a todo!() in the php-shim"]
+fn test_config_validator_warns_on_unnecessary_provide_replace() {
+ let warnings = validate(&fixture("composer_provide-replace-requirements.json"));
+
+ assert!(warnings.contains(
+ &"The package a/a in require is also listed in provide which satisfies the requirement. Remove it from provide if you wish to install it.".to_string()
+ ));
+ assert!(warnings.contains(
+ &"The package b/b in require is also listed in replace which satisfies the requirement. Remove it from replace if you wish to install it.".to_string()
+ ));
+ assert!(warnings.contains(
+ &"The package c/c in require-dev is also listed in provide which satisfies the requirement. Remove it from provide if you wish to install it.".to_string()
+ ));
+}
diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs
index e2a91b7..1bcc75e 100644
--- a/crates/shirabe/tests/util/main.rs
+++ b/crates/shirabe/tests/util/main.rs
@@ -1,3 +1,4 @@
+mod config_validator_test;
mod forgejo_url_test;
mod http;
mod platform_test;