diff options
Diffstat (limited to 'crates/shirabe')
| -rw-r--r-- | crates/shirabe/tests/command/diagnose_command_test.rs | 82 |
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); } |
