From f639066eaf49325fdbf1b697fb24c187b2d5038e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 26 Jun 2026 01:01:53 +0900 Subject: 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) --- .../tests/command/dump_autoload_command_test.rs | 375 +++++++++++++++++++-- 1 file changed, 351 insertions(+), 24 deletions(-) (limited to 'crates/shirabe/tests/command/dump_autoload_command_test.rs') diff --git a/crates/shirabe/tests/command/dump_autoload_command_test.rs b/crates/shirabe/tests/command/dump_autoload_command_test.rs index b3e79b3..1d302f5 100644 --- a/crates/shirabe/tests/command/dump_autoload_command_test.rs +++ b/crates/shirabe/tests/command/dump_autoload_command_test.rs @@ -1,73 +1,400 @@ //! ref: composer/tests/Composer/Test/Command/DumpAutoloadCommandTest.php +use crate::test_case::{RunOptions, get_application_tester, init_temp_composer}; +use regex::Regex; +use serial_test::serial; +use shirabe_php_shim::PhpMixed; + +/// ref: DumpAutoloadCommandTest::testDumpAutoload #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_dump_autoload() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![(PhpMixed::from("command"), PhpMixed::from("dump-autoload"))], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let output = app_tester.get_display(); + assert!(output.contains("Generating autoload files")); + assert!(output.contains("Generated autoload files")); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testDumpDevAutoload #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_dump_dev_autoload() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + (PhpMixed::from("--dev"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let output = app_tester.get_display(); + assert!(output.contains("Generating autoload files")); + assert!(output.contains("Generated autoload files")); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testDumpNoDevAutoload #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_dump_no_dev_autoload() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + (PhpMixed::from("--dev"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let output = app_tester.get_display(); + assert!(output.contains("Generating autoload files")); + assert!(output.contains("Generated autoload files")); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testUsingOptimizeAndStrictPsr #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_using_optimize_and_strict_psr() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + (PhpMixed::from("--optimize"), PhpMixed::from(true)), + (PhpMixed::from("--strict-psr"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let output = app_tester.get_display(); + assert!(output.contains("Generating optimized autoload files")); + let re = Regex::new(r"Generated optimized autoload files containing \d+ classes").unwrap(); + assert!(re.is_match(&output)); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testFailsUsingStrictPsrIfClassMapViolationsAreFound #[test] -#[ignore = "init_temp_composer / get_application_tester helpers not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_fails_using_strict_psr_if_class_map_violations_are_found() { - todo!() + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "autoload": { + "psr-4": { + "Application\\": "src", + }, + }, + })), + None, + None, + true, + ); + let dir = tear_down.working_dir(); + std::fs::create_dir(dir.join("src")).unwrap(); + std::fs::write( + dir.join("src/Foo.php"), + " \./src\)\. Skipping\.", + ) + .unwrap(); + assert!(re.is_match(&output)); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testUsingClassmapAuthoritative #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_using_classmap_authoritative() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + ( + PhpMixed::from("--classmap-authoritative"), + PhpMixed::from(true), + ), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let output = app_tester.get_display(); + assert!(output.contains("Generating optimized autoload files (authoritative)")); + let re = + Regex::new(r"Generated optimized autoload files \(authoritative\) containing \d+ classes") + .unwrap(); + assert!(re.is_match(&output)); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testUsingClassmapAuthoritativeAndStrictPsr #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_using_classmap_authoritative_and_strict_psr() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + ( + PhpMixed::from("--classmap-authoritative"), + PhpMixed::from(true), + ), + (PhpMixed::from("--strict-psr"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let output = app_tester.get_display(); + assert!(output.contains("Generating optimized autoload files")); + let re = + Regex::new(r"Generated optimized autoload files \(authoritative\) containing \d+ classes") + .unwrap(); + assert!(re.is_match(&output)); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testStrictPsrDoesNotWorkWithoutOptimizedAutoloader #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_strict_psr_does_not_work_without_optimized_autoloader() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let err = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + (PhpMixed::from("--strict-psr"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .expect_err("expected --strict-psr without optimize to error"); + assert!(err.to_string().contains( + "--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value." + )); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testDevAndNoDevCannotBeCombined #[test] -#[ignore = "ApplicationTester / get_application_tester helper not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_dev_and_no_dev_cannot_be_combined() { - todo!() + let tear_down = init_temp_composer(None, None, None, true); + + let mut app_tester = get_application_tester(); + let err = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("dump-autoload")), + (PhpMixed::from("--dev"), PhpMixed::from(true)), + (PhpMixed::from("--no-dev"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .expect_err("expected --dev and --no-dev combination to error"); + assert!( + err.to_string() + .contains("You can not use both --no-dev and --dev as they conflict with each other.") + ); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testWithCustomAutoloaderSuffix #[test] -#[ignore = "init_temp_composer / get_application_tester helpers not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_with_custom_autoloader_suffix() { - todo!() + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "config": { + "autoloader-suffix": "Foobar", + }, + })), + None, + None, + true, + ); + let dir = tear_down.working_dir(); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![(PhpMixed::from("command"), PhpMixed::from("dump-autoload"))], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let contents = std::fs::read_to_string(dir.join("vendor/autoload.php")).unwrap_or_default(); + assert!(contents.contains("ComposerAutoloaderInitFoobar")); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testWithExistingComposerLockAndAutoloaderSuffix #[test] -#[ignore = "init_temp_composer / get_application_tester helpers not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_with_existing_composer_lock_and_autoloader_suffix() { - todo!() + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "config": { + "autoloader-suffix": "Foobar", + }, + })), + None, + Some(&serde_json::json!({ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically", + ], + "content-hash": "d751713988987e9331980363e24189ce", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0", + })), + true, + ); + let dir = tear_down.working_dir(); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![(PhpMixed::from("command"), PhpMixed::from("dump-autoload"))], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let contents = std::fs::read_to_string(dir.join("vendor/autoload.php")).unwrap_or_default(); + assert!(contents.contains("ComposerAutoloaderInitFoobar")); + + drop(tear_down); } +/// ref: DumpAutoloadCommandTest::testWithExistingComposerLockWithoutAutoloaderSuffix #[test] -#[ignore = "init_temp_composer / get_application_tester helpers not implemented"] +#[serial] +#[ignore = "DumpAutoloadCommand::execute panics: composer_full_mut() holds a mut borrow of the composer RefCell across get_event_dispatcher().dispatch(), which re-enters via EventDispatcher::get_script_listeners -> PartialComposerHandle::borrow_partial (composer.rs:446) -> RefCell already mutably borrowed. Source bug in event_dispatcher.rs:1004 / dump_autoload_command.rs:88-91, not fixable from the test"] fn test_with_existing_composer_lock_without_autoloader_suffix() { - todo!() + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "name": "foo/bar", + })), + None, + Some(&serde_json::json!({ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically", + ], + "content-hash": "2d4a6be9a93712c5d6a119b26734a047", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0", + })), + true, + ); + let dir = tear_down.working_dir(); + + let mut app_tester = get_application_tester(); + let status_code = app_tester + .run( + vec![(PhpMixed::from("command"), PhpMixed::from("dump-autoload"))], + RunOptions::default(), + ) + .unwrap(); + assert_eq!(0, status_code); + + let contents = std::fs::read_to_string(dir.join("vendor/autoload.php")).unwrap_or_default(); + assert!(contents.contains("ComposerAutoloaderInit2d4a6be9a93712c5d6a119b26734a047")); + + drop(tear_down); } -- cgit v1.3.1