aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-28 15:03:29 +0900
committernsfisis <nsfisis@gmail.com>2026-06-28 15:03:29 +0900
commit3095fc5ca28ead2183422900b63064eeeed41fcf (patch)
tree0e3d7ad30247e8c0f3b9c2dab3c8874f0dfcbab0
parente97dc6e64c1be4bf78c420b11cec2a18dfd506d4 (diff)
downloadphp-shirabe-3095fc5ca28ead2183422900b63064eeeed41fcf.tar.gz
php-shirabe-3095fc5ca28ead2183422900b63064eeeed41fcf.tar.zst
php-shirabe-3095fc5ca28ead2183422900b63064eeeed41fcf.zip
test(command): port DiagnoseCommandTest cases
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
-rw-r--r--crates/shirabe/tests/command/diagnose_command_test.rs82
1 files changed, 80 insertions, 2 deletions
diff --git a/crates/shirabe/tests/command/diagnose_command_test.rs b/crates/shirabe/tests/command/diagnose_command_test.rs
index a8e6c16..1bd0c6a 100644
--- a/crates/shirabe/tests/command/diagnose_command_test.rs
+++ b/crates/shirabe/tests/command/diagnose_command_test.rs
@@ -1,15 +1,93 @@
//! ref: composer/tests/Composer/Test/Command/DiagnoseCommandTest.php
+use crate::test_case::{RunOptions, get_application_tester, init_temp_composer};
+use serial_test::serial;
+use shirabe::util::platform::Platform;
+use shirabe_php_shim::PhpMixed;
+
#[test]
+#[serial]
#[ignore = "diagnose checks live http/https connectivity to packagist and the github.com rate \
limit, so it requires real network access"]
fn test_cmd_fail() {
- todo!()
+ let tear_down = init_temp_composer(
+ Some(&serde_json::json!({ "name": "foo/bar", "description": "test pkg" })),
+ None,
+ None,
+ false,
+ );
+
+ let mut app_tester = get_application_tester();
+ app_tester
+ .run(
+ vec![(PhpMixed::from("command"), PhpMixed::from("diagnose"))],
+ RunOptions::default(),
+ )
+ .unwrap();
+
+ if Platform::get_env("COMPOSER_LOWEST_DEPS_TEST").as_deref() == Some("1") {
+ assert!(app_tester.get_status_code() >= 1);
+ } else {
+ assert_eq!(1, app_tester.get_status_code());
+ }
+
+ let output = app_tester.get_display();
+ assert!(output.contains(
+ "Checking composer.json: <warning>WARNING</warning>
+<warning>No license specified, it is recommended to do so. For closed-source software you may use \"proprietary\" as license.</warning>"
+ ));
+
+ assert!(output.contains(
+ "Checking http connectivity to packagist: OK
+Checking https connectivity to packagist: OK
+Checking github.com rate limit: "
+ ));
+
+ drop(tear_down);
}
#[test]
+#[serial]
#[ignore = "diagnose checks live http/https connectivity to packagist and the github.com rate \
limit, so it requires real network access"]
fn test_cmd_success() {
- todo!()
+ let tear_down = init_temp_composer(
+ Some(&serde_json::json!({
+ "name": "foo/bar",
+ "description": "test pkg",
+ "license": "MIT",
+ })),
+ None,
+ None,
+ false,
+ );
+
+ let mut app_tester = get_application_tester();
+ app_tester
+ .run(
+ vec![(PhpMixed::from("command"), PhpMixed::from("diagnose"))],
+ RunOptions::default(),
+ )
+ .unwrap();
+
+ if Platform::get_env("COMPOSER_LOWEST_DEPS_TEST").as_deref() != Some("1") {
+ // assertCommandIsSuccessful
+ assert_eq!(
+ 0,
+ app_tester.get_status_code(),
+ "{}",
+ app_tester.get_display()
+ );
+ }
+
+ let output = app_tester.get_display();
+ assert!(output.contains("Checking composer.json: OK"));
+
+ assert!(output.contains(
+ "Checking http connectivity to packagist: OK
+Checking https connectivity to packagist: OK
+Checking github.com rate limit: "
+ ));
+
+ drop(tear_down);
}