From 759b2980e70dfb8960238f75d68bb6dddce25414 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 7 Aug 2026 07:01:50 +0900 Subject: test: port the tests left as todo!() stubs Replace the todo!() bodies with real ports. Four autoload-generator tests now run for real; the rest stay #[ignore]d, but each ignore reason now names the concrete missing symbol instead of a vague subsystem. Production additions the ports need: the deprecated AuthHelper::addAuthenticationHeader wrapper, EventDispatcher::__set_dispatch_script_override as the seam for PHPUnit onlyMethods(['dispatchScript']), and a define() stub in the shim. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/tests/autoload/class_loader_test.rs | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/tests/autoload/class_loader_test.rs') diff --git a/crates/shirabe/tests/autoload/class_loader_test.rs b/crates/shirabe/tests/autoload/class_loader_test.rs index 582e24fa..998683c9 100644 --- a/crates/shirabe/tests/autoload/class_loader_test.rs +++ b/crates/shirabe/tests/autoload/class_loader_test.rs @@ -1,13 +1,37 @@ //! ref: composer/tests/Composer/Test/Autoload/ClassLoaderTest.php use shirabe::autoload::class_loader::ClassLoader; +use shirabe_php_shim::class_exists; + +/// ref: ClassLoaderTest::getLoadClassTests +fn get_load_class_tests() -> Vec<&'static str> { + vec![ + "Namespaced\\Foo", + "Pearlike_Foo", + "ShinyVendor\\ShinyPackage\\SubNamespace\\Foo", + ] +} #[test] -#[ignore = "depends on PHP runtime class_exists() to verify loadClass defined a class; no Rust equivalent"] +#[ignore = "shirabe_php_shim::class_exists models a fixed set of classes available in a PHP CLI environment; loadClass cannot add to it because including a PHP file does not define a class on the Rust side"] fn test_load_class() { - // TODO(phase-d): loadClass() include()s a fixture and PHPUnit asserts via class_exists(); - // Rust has no equivalent of runtime class definition/loading. - todo!() + let fixtures = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../composer/tests/Composer/Test/Autoload/Fixtures") + .canonicalize() + .unwrap() + .display() + .to_string(); + + for class in get_load_class_tests() { + let mut loader = ClassLoader::new(None); + loader.add("Namespaced\\", vec![fixtures.clone()], false); + loader.add("Pearlike_", vec![fixtures.clone()], false); + loader + .add_psr4("ShinyVendor\\ShinyPackage\\", vec![fixtures.clone()], false) + .unwrap(); + loader.load_class(class); + assert!(class_exists(class), "->loadClass() loads '{}'", class); + } } #[test] @@ -17,9 +41,10 @@ fn test_get_prefixes_with_no_psr0_configuration() { } #[test] -#[ignore = "depends on PHP serialize()/unserialize() round-trip of ClassLoader; no Rust equivalent"] +#[ignore = "the round trip is `unserialize(serialize($loader))`: shirabe_php_shim::serialize takes a PhpMixed (a ClassLoader cannot be turned into one) and there is no unserialize at all, so the ClassLoader under test cannot be round-tripped"] fn test_serializability() { - // TODO(phase-d): serializes/unserializes the ClassLoader and compares every getter; PHP - // serialize()/unserialize() has no Rust equivalent here. + // TODO(phase-d): the round trip is `unserialize(serialize($loader))`. serialize() in the shim + // takes a PhpMixed, which a ClassLoader cannot be converted into, and there is no unserialize + // symbol to produce the second ClassLoader the assertions compare against. todo!() } -- cgit v1.3.1