aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/autoload/class_loader_test.rs
blob: 998683c9ab8ddd4affcc67ac7d533627c0a4b00c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! 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 = "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() {
    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]
fn test_get_prefixes_with_no_psr0_configuration() {
    let loader = ClassLoader::new(None);
    assert!(loader.get_prefixes().is_empty());
}

#[test]
#[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): 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!()
}