aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/plugin/plugin_installer_test.rs
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 /crates/shirabe/tests/plugin/plugin_installer_test.rs
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>
Diffstat (limited to 'crates/shirabe/tests/plugin/plugin_installer_test.rs')
-rw-r--r--crates/shirabe/tests/plugin/plugin_installer_test.rs27
1 files changed, 1 insertions, 26 deletions
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"))