diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-26 01:01:53 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-26 01:01:53 +0900 |
| commit | f639066eaf49325fdbf1b697fb24c187b2d5038e (patch) | |
| tree | 7444d076aec641916766c29e8ced5cb6177c2a15 /crates/shirabe/tests/command/run_script_command_test.rs | |
| parent | 5f9778e6988b43a759d976322dd73dcac7ff927d (diff) | |
| download | php-shirabe-f639066eaf49325fdbf1b697fb24c187b2d5038e.tar.gz php-shirabe-f639066eaf49325fdbf1b697fb24c187b2d5038e.tar.zst php-shirabe-f639066eaf49325fdbf1b697fb24c187b2d5038e.zip | |
test(command): port command test bodies from Composer PHPUnit suite
Faithfully port repository, base_dependency, exec, dump_autoload, run_script,
licenses command tests from their PHP counterparts (expected values verbatim).
Newly passing: repository (6), base_dependency (5), exec (2). Tests whose ported
bodies hit a genuine unported path (HTTP/curl, event-dispatch re-entrancy,
spl_autoload_register, php_uname, instance_of, un-delimited Preg patterns,
Config::merge dropping list repos) keep faithful bodies but stay #[ignore] with
precise reasons; no assertions weakened.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/command/run_script_command_test.rs')
| -rw-r--r-- | crates/shirabe/tests/command/run_script_command_test.rs | 101 |
1 files changed, 95 insertions, 6 deletions
diff --git a/crates/shirabe/tests/command/run_script_command_test.rs b/crates/shirabe/tests/command/run_script_command_test.rs index 366ee96..8e96cf3 100644 --- a/crates/shirabe/tests/command/run_script_command_test.rs +++ b/crates/shirabe/tests/command/run_script_command_test.rs @@ -1,31 +1,120 @@ //! ref: composer/tests/Composer/Test/Command/RunScriptCommandTest.php +use crate::test_case::{RunOptions, get_application_tester, init_temp_composer}; +use serial_test::serial; +use shirabe_php_shim::PhpMixed; + #[test] #[ignore = "requires PHPUnit getMockBuilder/onlyMethods partial mock of RunScriptCommand (override requireComposer/initialize/etc) plus expects()/with()/willReturn()/returnValueMap mocks of InputInterface/OutputInterface/EventDispatcher with a callback constraint on ScriptEvent; no mocking infrastructure exists"] fn test_detect_and_pass_dev_mode_to_event_and_to_dispatching() { todo!() } +/// ref: RunScriptCommandTest::testCanListScripts #[test] -#[ignore = "requires init_temp_composer and get_application_tester (ApplicationTester) infrastructure; neither exists"] +#[serial] +#[ignore = "Application::do_run registers composer.json scripts as commands; that path calls loader.register (class_loader.rs:288 -> spl_autoload_register at runtime.rs:231) which is a todo!() stub. With a 'scripts' key present, app_tester.run() panics there before the command executes"] fn test_can_list_scripts() { - todo!() + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "scripts": { + "test": "@php test", + "fix-cs": "php-cs-fixer fix", + }, + "scripts-descriptions": { + "fix-cs": "Run the codestyle fixer", + }, + })), + None, + None, + true, + ); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("run-script")), + (PhpMixed::from("--list"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code, "assertCommandIsSuccessful"); + + let output = app_tester.get_display(); + + assert!( + output.contains("Runs the test script as defined in composer.json"), + "The default description for the test script should be printed" + ); + assert!( + output.contains("Run the codestyle fixer"), + "The custom description for the fix-cs script should be printed" + ); + + drop(tear_down); } +/// ref: RunScriptCommandTest::testCanDefineAliases #[test] -#[ignore = "requires init_temp_composer and get_application_tester (ApplicationTester) infrastructure; neither exists"] +#[serial] +#[ignore = "Application::do_run registers composer.json scripts as commands; that path calls loader.register (class_loader.rs:288 -> spl_autoload_register at runtime.rs:231) which is a todo!() stub. With a 'scripts' key present, app_tester.run() panics there before the command executes"] fn test_can_define_aliases() { - todo!() + let expected_aliases = vec!["one", "two", "three"]; + + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "scripts": { + "test": "@php test", + }, + "scripts-aliases": { + "test": expected_aliases, + }, + })), + None, + None, + true, + ); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("test")), + (PhpMixed::from("--help"), PhpMixed::from(true)), + (PhpMixed::from("--format"), PhpMixed::from("json")), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code, "assertCommandIsSuccessful"); + + let output = app_tester.get_display(); + let array: serde_json::Value = serde_json::from_str(&output).unwrap(); + let mut actual_aliases: Vec<serde_json::Value> = array["usage"].as_array().unwrap().clone(); + actual_aliases.remove(0); + + let expected: Vec<serde_json::Value> = expected_aliases + .iter() + .map(|s| serde_json::Value::String(s.to_string())) + .collect(); + assert_eq!( + expected, actual_aliases, + "The custom aliases for the test command should be printed" + ); + + drop(tear_down); } #[test] -#[ignore = "requires init_temp_composer/get_application_tester (ApplicationTester) plus writing and executing a PHP-generated Symfony Command class (file_put_contents MyCommand.php); fundamentally unportable, no infrastructure exists"] +#[ignore = "requires writing and executing a PHP-generated Symfony Command class (file_put_contents MyCommand.php) loaded via composer autoload; fundamentally unportable, no PHP runtime command loading in shirabe"] fn test_execution_of_simple_symfony_command() { todo!() } #[test] -#[ignore = "requires init_temp_composer/get_application_tester (ApplicationTester) plus writing and executing a PHP-generated Symfony Command class (file_put_contents MyCommandWithDefinitions.php); fundamentally unportable, no infrastructure exists"] +#[ignore = "requires writing and executing a PHP-generated Symfony Command class (file_put_contents MyCommandWithDefinitions.php) loaded via composer autoload; fundamentally unportable, no PHP runtime command loading in shirabe"] fn test_execution_of_symfony_command_with_configuration() { todo!() } |
