diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-27 17:21:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-27 17:26:28 +0900 |
| commit | e98823e599eb375b30037cc714710e3309d927d1 (patch) | |
| tree | e1689ec164086798fc46aa6a58d1e914cf4873b2 /crates/shirabe/src/platform | |
| parent | 20f620bdd0b5764ed2e9812dc0772f907b0d6f29 (diff) | |
| download | php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.tar.gz php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.tar.zst php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.zip | |
test: port Composer tests unblocked by mockall, add seams
Port 11 categories of previously-ignored Composer tests now reachable with
the mockall crate: DownloadManager, VCS/Perforce/File downloaders,
VersionSelector, PlatformRepository, Auditor, installer/FilesystemRepository,
RootPackageLoader, util auth/http, commands, and Cache.
Extract test seams additively on concrete structs as *Interface traits
(Runtime, HhvmDetector, VersionGuesser, RepositorySet, Perforce,
BinaryInstaller) plus mock-field seams (Cache, Filesystem); consumers take
trait objects. Mocks are defined locally in the test crates via
mockall::mock!, since automock-generated mocks are cfg(test)-gated and
invisible across the integration-test boundary.
dataProviders are ported in full; tests blocked by unported shims stay
#[ignore] with documented reasons rather than reduced or weakened.
Fix product bugs surfaced by the ports:
- util/github: use the exception code, not the HTTP status, for 401/403
- advisory: serialize empty audit maps as [] to match PHP json_encode
- repository/filesystem and downloader/file: fix RefCell double-borrow panics
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/platform')
| -rw-r--r-- | crates/shirabe/src/platform/hhvm_detector.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/platform/runtime.rs | 58 |
2 files changed, 50 insertions, 22 deletions
diff --git a/crates/shirabe/src/platform/hhvm_detector.rs b/crates/shirabe/src/platform/hhvm_detector.rs index da062d5..69871f1 100644 --- a/crates/shirabe/src/platform/hhvm_detector.rs +++ b/crates/shirabe/src/platform/hhvm_detector.rs @@ -9,6 +9,14 @@ use std::sync::Mutex; // None = null (uninitialized), Some(None) = false (not found), Some(Some(v)) = version static HHVM_VERSION_CACHE: Mutex<Option<Option<String>>> = Mutex::new(None); +/// Seam over HHVM detection so PlatformRepository can be tested with a mocked version. +/// PHP mocks the concrete `Composer\Platform\HhvmDetector` directly; the trait is +/// introduced here to keep the consumer dependent only on trait methods. +pub trait HhvmDetectorInterface: std::fmt::Debug { + fn reset(&self); + fn get_version(&mut self) -> Option<String>; +} + #[derive(Debug)] pub struct HhvmDetector { executable_finder: Option<ExecutableFinder>, @@ -25,12 +33,14 @@ impl HhvmDetector { process_executor, } } +} - pub fn reset(&self) { +impl HhvmDetectorInterface for HhvmDetector { + fn reset(&self) { *HHVM_VERSION_CACHE.lock().unwrap() = None; } - pub fn get_version(&mut self) -> Option<String> { + fn get_version(&mut self) -> Option<String> { let cached = HHVM_VERSION_CACHE.lock().unwrap().clone(); if cached.is_some() { return cached.flatten(); diff --git a/crates/shirabe/src/platform/runtime.rs b/crates/shirabe/src/platform/runtime.rs index aa2f4d7..fcee930 100644 --- a/crates/shirabe/src/platform/runtime.rs +++ b/crates/shirabe/src/platform/runtime.rs @@ -8,41 +8,53 @@ use shirabe_php_shim::{ html_entity_decode, implode, instantiate_class, ltrim, phpversion, strip_tags, trim, }; +/// Seam over the PHP runtime so PlatformRepository can be tested against mocked +/// extension/constant/function probes. PHP has no such interface (the test mocks the +/// concrete `Composer\Platform\Runtime` directly); it is introduced here to keep the +/// consumer dependent only on trait methods. +pub trait RuntimeInterface: std::fmt::Debug { + fn has_constant(&self, constant_name: &str, class: Option<String>) -> bool; + fn get_constant(&self, constant_name: &str, class: Option<String>) -> PhpMixed; + /// `callable` carries the PHP callable spec (a function name string or a + /// `[class, method]` list), matching PHP `invoke($callable, $arguments)`. + fn invoke(&self, callable: PhpMixed, arguments: Vec<PhpMixed>) -> PhpMixed; + fn has_class(&self, class: &str) -> bool; + fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> Result<PhpMixed>; + fn get_extensions(&self) -> Vec<String>; + fn get_extension_version(&self, extension: &str) -> String; + fn get_extension_info(&self, extension: &str) -> Result<String>; +} + #[derive(Debug)] pub struct Runtime; -impl Runtime { - pub fn has_constant(&self, constant_name: &str, class: Option<&str>) -> bool { +impl RuntimeInterface for Runtime { + fn has_constant(&self, constant_name: &str, class: Option<String>) -> bool { defined(<rim( - &format!("{}::{}", class.unwrap_or(""), constant_name), + &format!("{}::{}", class.as_deref().unwrap_or(""), constant_name), Some(":"), )) } - pub fn get_constant(&self, constant_name: &str, class: Option<&str>) -> PhpMixed { + fn get_constant(&self, constant_name: &str, class: Option<String>) -> PhpMixed { constant(<rim( - &format!("{}::{}", class.unwrap_or(""), constant_name), + &format!("{}::{}", class.as_deref().unwrap_or(""), constant_name), Some(":"), )) } - pub fn has_function(&self, f: &str) -> bool { - function_exists(f) - } - - pub fn invoke( - &self, - callable: Box<dyn Fn(Vec<PhpMixed>) -> PhpMixed>, - arguments: Vec<PhpMixed>, - ) -> PhpMixed { - callable(arguments) + fn invoke(&self, callable: PhpMixed, arguments: Vec<PhpMixed>) -> PhpMixed { + // PHP: return $callable(...$arguments); + // Dispatching an arbitrary PHP callable needs a PHP runtime; no shim exists. + let _ = (callable, arguments); + todo!() } - pub fn has_class(&self, class: &str) -> bool { + fn has_class(&self, class: &str) -> bool { class_exists(class) } - pub fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> Result<PhpMixed> { + fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> Result<PhpMixed> { if arguments.is_empty() { Ok(instantiate_class(class, vec![])) } else { @@ -50,20 +62,26 @@ impl Runtime { } } - pub fn get_extensions(&self) -> Vec<String> { + fn get_extensions(&self) -> Vec<String> { get_loaded_extensions() } - pub fn get_extension_version(&self, extension: &str) -> String { + fn get_extension_version(&self, extension: &str) -> String { let version = phpversion(extension); version.unwrap_or_else(|| "0".to_string()) } - pub fn get_extension_info(&self, extension: &str) -> Result<String> { + fn get_extension_info(&self, extension: &str) -> Result<String> { // Depends on \ReflectionExtension::info() and output buffering; no shim equivalent exists. let _ = extension; todo!() } +} + +impl Runtime { + pub fn has_function(&self, f: &str) -> bool { + function_exists(f) + } pub fn parse_html_extension_info(html: &str) -> String { let mut result: Vec<String> = vec![]; |
