Файли
openidea/crates/ide-host/tests/container_php_real.rs
T
Sameh Elhawaryтаsamehelhawary a8773a196c feat(php): show the version and Xdebug of a container run target's PHP (#7612)
When PHP runs in a Docker or Compose run target, Settings › PHP shows the version and Xdebug of the PHP in the container instead of this machine's. The IDE runs the target's PHP once in a removed container (entrypoint and service dependencies skipped, XDEBUG_MODE=off), keeps the answer per project and target configuration, and reads it again on refresh. php_probe_args shares the run/compose run part with the Python probe.

Refs #4582

Co-authored-by: samehelhawary <[email protected]>
2026-12-03 15:54:37 +08:00

53 рядки
2.5 KiB
Rust

//! The PHP of a Docker and of a Compose run target, against a real daemon. Ignored by default:
//! `docker` with the Compose plugin must be on `PATH` and able to pull `php:8.3-cli`.
mod common;
use ide_host::{Host, ops};
use std::sync::Arc;
const WINDOW: &str = "main";
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[ignore = "requires a Docker daemon"]
async fn reads_the_php_of_docker_and_compose_targets() {
let project = tempfile::tempdir().unwrap();
let root = dunce::canonicalize(project.path()).unwrap();
std::fs::write(root.join("compose.yaml"), "services:\n app:\n image: php:8.3-cli\n").unwrap();
let state = tempfile::tempdir().unwrap();
let host = Arc::new(Host::new(common::host_config(state.path())));
host.trust.decide(&root, true, false).unwrap();
host.open_project(WINDOW, &root).unwrap();
let targets = serde_json::json!([
{ "kind": "docker", "id": "image", "name": "PHP image", "image": "php:8.3-cli" },
{ "kind": "compose", "id": "app", "name": "Compose app", "service": "app" },
{ "kind": "docker", "id": "none", "name": "No PHP", "image": "php:8.3-cli", "php": "/opt/missing/php" },
{ "kind": "ssh", "id": "box", "name": "Box" },
]);
ops::project::set_settings(
&host,
WINDOW,
ide_workspace::settings::SettingsScope::Project,
"runTargets",
&targets.to_string(),
)
.unwrap();
for (id, name) in [("image", "PHP image"), ("app", "Compose app")] {
let php = ops::sdk::sdk_container_php(&host, WINDOW, id.into(), false).await.unwrap();
eprintln!("{id}: {php:?}");
assert_eq!((php.target.as_str(), php.name.as_str()), (id, name));
assert!(php.php_version.starts_with("8.3."), "{php:?}");
assert_eq!(php.xdebug, None, "the official image has no Xdebug");
// The answer is kept, and asked again on refresh.
assert_eq!(ops::sdk::sdk_container_php(&host, WINDOW, id.into(), false).await.unwrap(), php);
assert_eq!(ops::sdk::sdk_container_php(&host, WINDOW, id.into(), true).await.unwrap(), php);
}
let missing = ops::sdk::sdk_container_php(&host, WINDOW, "none".into(), false).await.unwrap_err();
eprintln!("no php: {}", missing.message);
assert!(missing.message.contains("/opt/missing/php"), "{}", missing.message);
let ssh = ops::sdk::sdk_container_php(&host, WINDOW, "box".into(), false).await.unwrap_err();
assert!(ssh.message.contains("not a container"), "{}", ssh.message);
}