aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/autoload/class_loader_test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/tests/autoload/class_loader_test.rs')
-rw-r--r--crates/shirabe/tests/autoload/class_loader_test.rs39
1 files changed, 32 insertions, 7 deletions
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!()
}