aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc/tests/generated_stubs.rs
blob: b4ff8197cef94699a39b068d152dcd23b197181d (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
//! Freshness check for the generated proxy stubs: `generate-stubs --check` verifies that the
//! committed stub files and the `STUB_FILES` list in `lib.rs` match what the generator emits
//! from the current Composer checkout and classifier report.
//!
//! The generator needs a PHP interpreter, its composer vendor directory and the classifier
//! report; when any of those is missing the test returns early, following the non-mock test
//! convention of this crate.

use shirabe_external_packages::symfony::process::PhpExecutableFinder;
use std::path::Path;

#[test]
fn generated_stubs_are_fresh() {
    let Some(php) = PhpExecutableFinder::new().find(false) else {
        return;
    };
    let tool_dir =
        Path::new(env!("CARGO_MANIFEST_DIR")).join("../../scripts/plugin-stub-generator");
    if !tool_dir.join("vendor/autoload.php").is_file() {
        return;
    }
    if !tool_dir
        .join("../plugin-class-classifier/report.json")
        .is_file()
    {
        return;
    }

    let output = std::process::Command::new(php)
        .arg(tool_dir.join("generate-stubs"))
        .arg("--check")
        .output()
        .expect("failed to spawn the stub generator");
    assert!(
        output.status.success(),
        "generate-stubs --check failed; regenerate the stubs with \
         scripts/plugin-stub-generator/generate-stubs:\n{}",
        String::from_utf8_lossy(&output.stderr),
    );
}