aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 16:26:10 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 17:34:46 +0900
commit7e7837a559310792dcf312e0c52857450ed781dc (patch)
tree458100fc10851c6e899d30478369dc791543b73c
parenta9b45cc01afa726bf9acd7f30ad3235593a258e2 (diff)
downloadphp-shirabe-7e7837a559310792dcf312e0c52857450ed781dc.tar.gz
php-shirabe-7e7837a559310792dcf312e0c52857450ed781dc.tar.zst
php-shirabe-7e7837a559310792dcf312e0c52857450ed781dc.zip
refactor(tests): share the PHP worker helpers with the plugin binary
plugin_installer_test.rs carried its own copy of php_runtime_available, lock_php_worker and load_composer_php_runtime, and the other ten files in the binary imported them from there. The bodies matched tests/common/php_worker.rs, so include that instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-rw-r--r--crates/shirabe/tests/plugin/alias_package_test.rs3
-rw-r--r--crates/shirabe/tests/plugin/e2e_command_provider_test.rs2
-rw-r--r--crates/shirabe/tests/plugin/e2e_installer_test.rs2
-rw-r--r--crates/shirabe/tests/plugin/e2e_installers_test.rs2
-rw-r--r--crates/shirabe/tests/plugin/e2e_normalize_test.rs2
-rw-r--r--crates/shirabe/tests/plugin/e2e_package_event_test.rs2
-rw-r--r--crates/shirabe/tests/plugin/e2e_script_command_test.rs2
-rw-r--r--crates/shirabe/tests/plugin/main.rs2
-rw-r--r--crates/shirabe/tests/plugin/plugin_installer_test.rs27
-rw-r--r--crates/shirabe/tests/plugin/subscriber_test.rs3
-rw-r--r--crates/shirabe/tests/plugin/value_round_trip_test.rs3
11 files changed, 15 insertions, 35 deletions
diff --git a/crates/shirabe/tests/plugin/alias_package_test.rs b/crates/shirabe/tests/plugin/alias_package_test.rs
index b32d2b67..e566ff7b 100644
--- a/crates/shirabe/tests/plugin/alias_package_test.rs
+++ b/crates/shirabe/tests/plugin/alias_package_test.rs
@@ -3,7 +3,8 @@
//! Shirabe-owned.
use crate::async_runtime::run;
-use crate::plugin_installer_test::{lock_php_worker, new_installer, php_runtime_available, set_up};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
+use crate::plugin_installer_test::{new_installer, set_up};
use shirabe::installer::InstallerInterface;
use shirabe::package::loader::{ArrayLoader, JsonLoader, JsonLoaderInput};
use shirabe::package::{
diff --git a/crates/shirabe/tests/plugin/e2e_command_provider_test.rs b/crates/shirabe/tests/plugin/e2e_command_provider_test.rs
index 4d04fb22..c8ae81c5 100644
--- a/crates/shirabe/tests/plugin/e2e_command_provider_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_command_provider_test.rs
@@ -7,7 +7,7 @@
//! fetched; the test skips only while the PHP runtime or the Composer checkout is missing.
use crate::e2e_extension_installer_test::{copy_dir, upstream_composer_bin};
-use crate::plugin_installer_test::{lock_php_worker, php_runtime_available};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
diff --git a/crates/shirabe/tests/plugin/e2e_installer_test.rs b/crates/shirabe/tests/plugin/e2e_installer_test.rs
index dadb5b59..934337f2 100644
--- a/crates/shirabe/tests/plugin/e2e_installer_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_installer_test.rs
@@ -7,7 +7,7 @@
//! fetched; the test skips only while the PHP runtime or the Composer checkout is missing.
use crate::e2e_extension_installer_test::{copy_dir, upstream_composer_bin};
-use crate::plugin_installer_test::{lock_php_worker, php_runtime_available};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
diff --git a/crates/shirabe/tests/plugin/e2e_installers_test.rs b/crates/shirabe/tests/plugin/e2e_installers_test.rs
index 9d8693fb..ade69d90 100644
--- a/crates/shirabe/tests/plugin/e2e_installers_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_installers_test.rs
@@ -6,7 +6,7 @@
//! test skips itself while that directory, the PHP runtime or the Composer checkout is missing.
use crate::e2e_extension_installer_test::{copy_dir, upstream_composer_bin};
-use crate::plugin_installer_test::{lock_php_worker, php_runtime_available};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
diff --git a/crates/shirabe/tests/plugin/e2e_normalize_test.rs b/crates/shirabe/tests/plugin/e2e_normalize_test.rs
index 9fb49bab..6cc6b05c 100644
--- a/crates/shirabe/tests/plugin/e2e_normalize_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_normalize_test.rs
@@ -8,7 +8,7 @@
//! The test skips while any of these is missing; test runs themselves are offline.
use crate::e2e_extension_installer_test::{copy_dir, upstream_composer_bin};
-use crate::plugin_installer_test::{lock_php_worker, php_runtime_available};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
diff --git a/crates/shirabe/tests/plugin/e2e_package_event_test.rs b/crates/shirabe/tests/plugin/e2e_package_event_test.rs
index a6569105..69085f35 100644
--- a/crates/shirabe/tests/plugin/e2e_package_event_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_package_event_test.rs
@@ -6,7 +6,7 @@
//! missing.
use crate::e2e_extension_installer_test::{copy_dir, upstream_composer_bin};
-use crate::plugin_installer_test::{lock_php_worker, php_runtime_available};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
diff --git a/crates/shirabe/tests/plugin/e2e_script_command_test.rs b/crates/shirabe/tests/plugin/e2e_script_command_test.rs
index d730fbff..2fcf47ec 100644
--- a/crates/shirabe/tests/plugin/e2e_script_command_test.rs
+++ b/crates/shirabe/tests/plugin/e2e_script_command_test.rs
@@ -7,7 +7,7 @@
//! fetched; the test skips only while the PHP runtime or the Composer checkout is missing.
use crate::e2e_extension_installer_test::{copy_dir, upstream_composer_bin};
-use crate::plugin_installer_test::{lock_php_worker, php_runtime_available};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
diff --git a/crates/shirabe/tests/plugin/main.rs b/crates/shirabe/tests/plugin/main.rs
index 8c0b394d..d8defcbc 100644
--- a/crates/shirabe/tests/plugin/main.rs
+++ b/crates/shirabe/tests/plugin/main.rs
@@ -2,6 +2,8 @@
mod async_runtime;
#[path = "../common/config_stub.rs"]
mod config_stub;
+#[path = "../common/php_worker.rs"]
+mod php_worker;
mod alias_package_test;
mod e2e_command_provider_test;
diff --git a/crates/shirabe/tests/plugin/plugin_installer_test.rs b/crates/shirabe/tests/plugin/plugin_installer_test.rs
index 346bf5c6..42b2f5b6 100644
--- a/crates/shirabe/tests/plugin/plugin_installer_test.rs
+++ b/crates/shirabe/tests/plugin/plugin_installer_test.rs
@@ -1,6 +1,7 @@
//! ref: composer/tests/Composer/Test/Plugin/PluginInstallerTest.php
use crate::async_runtime::run;
+use crate::php_worker::{load_composer_php_runtime, lock_php_worker, php_runtime_available};
use indexmap::IndexMap;
use shirabe::autoload::AutoloadGenerator;
use shirabe::composer::{Composer, ComposerHandle, PartialOrFullComposer};
@@ -36,34 +37,8 @@ use shirabe_php_shim::Catch as _;
use shirabe_php_shim::PhpMixed;
use shirabe_semver::VersionParser;
use shirabe_symfony_console::output::VERBOSITY_NORMAL;
-use shirabe_symfony_process::PhpExecutableFinder;
use tempfile::TempDir;
-/// The register/activate flow runs the plugin in the real PHP worker; without a PHP binary the
-/// worker cannot start. Tests exercising it return early, following the convention of the
-/// non-mock tests in `shirabe-php-rpc`.
-pub(crate) fn php_runtime_available() -> bool {
- PhpExecutableFinder::new().find(false).is_some()
-}
-
-/// All tests in this binary share the single PHP worker, whose loaded-class table persists
-/// across tests just like PHPUnit's single-process runs (that sharing is what exercises the
-/// `_composer_tmp` rename path). Interleaving two tests would let one test's class definitions
-/// race the other's `class_exists` checks, so the worker-touching tests run serialized.
-static PHP_WORKER_TESTS: std::sync::Mutex<()> = std::sync::Mutex::new(());
-
-pub(crate) fn lock_php_worker() -> std::sync::MutexGuard<'static, ()> {
- PHP_WORKER_TESTS
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
-}
-
-fn load_composer_php_runtime() {
- static CACHE: std::sync::OnceLock<TempDir> = std::sync::OnceLock::new();
- let cache = CACHE.get_or_init(|| tempfile::tempdir().expect("no cache directory for the test"));
- EventDispatcher::__ensure_composer_php_runtime(cache.path()).unwrap();
-}
-
/// `__DIR__ . '/Fixtures'` of the upstream test class.
fn fixtures_dir() -> String {
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
diff --git a/crates/shirabe/tests/plugin/subscriber_test.rs b/crates/shirabe/tests/plugin/subscriber_test.rs
index a08d8d8d..1df4f0e8 100644
--- a/crates/shirabe/tests/plugin/subscriber_test.rs
+++ b/crates/shirabe/tests/plugin/subscriber_test.rs
@@ -3,7 +3,8 @@
//! these tests use a Shirabe-owned fixture (`fixtures/subscriber-v1`) instead of a ported one.
use crate::async_runtime::run;
-use crate::plugin_installer_test::{lock_php_worker, new_installer, php_runtime_available, set_up};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
+use crate::plugin_installer_test::{new_installer, set_up};
use shirabe::installer::InstallerInterface;
use shirabe::package::PackageInterfaceHandle;
use shirabe::package::loader::{ArrayLoader, JsonLoader, JsonLoaderInput};
diff --git a/crates/shirabe/tests/plugin/value_round_trip_test.rs b/crates/shirabe/tests/plugin/value_round_trip_test.rs
index 3e01422a..51ff2899 100644
--- a/crates/shirabe/tests/plugin/value_round_trip_test.rs
+++ b/crates/shirabe/tests/plugin/value_round_trip_test.rs
@@ -4,7 +4,8 @@
//! in-process), so the fixture `fixtures/values-v1` is Shirabe-owned.
use crate::async_runtime::run;
-use crate::plugin_installer_test::{lock_php_worker, new_installer, php_runtime_available, set_up};
+use crate::php_worker::{lock_php_worker, php_runtime_available};
+use crate::plugin_installer_test::{new_installer, set_up};
use indexmap::IndexMap;
use shirabe::installer::InstallerInterface;
use shirabe::package::Link;