From 8117e5450693d19726da877bce8aacf5c7aa53af Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 25 Jun 2026 15:12:06 +0900 Subject: test: port 44 vcs/downloader/version tests using mock infra Port git, version_guesser, gitlab_driver, github_driver, and git_downloader tests using the ProcessExecutor/HttpDownloader mocks and IO/Config stubs. Fix production regex-porting bugs surfaced by the now-reachable paths: Url::sanitize and Response::find_header_value had non-delimited PCRE patterns; implement array_search_mixed non-strict branch and a datetime format mapping. Add HttpDownloader::__new_mock so mocked downloaders skip curl construction. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/util/git.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'crates/shirabe/src/util/git.rs') diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index f031157..142d5e2 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -132,6 +132,19 @@ impl Git { self.run_command(callables, url, cwd, initial_clone, command_output) } + /// For testing only. Public seam over the (deprecated) private `run_command`, + /// mirroring `Git::runCommand` as exercised by `GitTest`. + pub fn __run_command( + &mut self, + command_callable: Vec Vec>>, + url: &str, + cwd: Option<&str>, + initial_clone: bool, + command_output: Option<&mut PhpMixed>, + ) -> Result<()> { + self.run_command(command_callable, url, cwd, initial_clone, command_output) + } + /// @param callable|array $commandCallable /// @param mixed $commandOutput the output will be written into this var if passed by ref /// if a callable is passed it will be used as output handler @@ -1310,6 +1323,22 @@ impl Git { version.clone().unwrap_or(None) } + /// For testing only. Resets the cached git `version` static so the next + /// `get_version` call re-runs `git --version`, mirroring the + /// `ReflectionProperty(GitUtil::class, 'version')->setValue(null, false)` + /// done in VersionGuesserTest's setUp/tearDown. + pub fn __reset_version() { + *VERSION.lock().unwrap() = None; + } + + /// For testing only. Seeds the cached git `version` static, mirroring the + /// `ReflectionProperty(GitUtil::class, 'version')->setValue(null, $version)` + /// done in GitDownloaderTest's `initGitVersion`. `Some(v)` records a detected + /// version; `None` records that git is unavailable, both without shelling out. + pub fn __set_version(version: Option) { + *VERSION.lock().unwrap() = Some(version); + } + /// @param string[] $credentials fn mask_credentials(&self, error: &str, credentials: &[String]) -> String { let mut masked_credentials: Vec = vec![]; -- cgit v1.3.1