aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-20 01:33:14 +0900
committernsfisis <nsfisis@gmail.com>2026-07-20 01:33:14 +0900
commit5fac1bba14ad5b9e4d2abfa3ca299f88cc1e62bf (patch)
tree895d808df734f16b6201e610739a67dfa317d11d /crates/shirabe/tests/command
parent9a2cee2532e5d28d5cea5726f35ab3c7046e7c0d (diff)
downloadphp-shirabe-5fac1bba14ad5b9e4d2abfa3ca299f88cc1e62bf.tar.gz
php-shirabe-5fac1bba14ad5b9e4d2abfa3ca299f88cc1e62bf.tar.zst
php-shirabe-5fac1bba14ad5b9e4d2abfa3ca299f88cc1e62bf.zip
fix(process-executor): un-ignore 11 tests by implementing execute_async mock support
ProcessExecutor::execute_async's mock branch was an unimplemented todo!(), blocking every test whose code path calls it (feature-branch git diffing, system-unzip/7z fallback extraction). Implement it by: - Adding Process::__mock (mirroring the existing ZipArchive::__mock pattern) so execute_async can resolve with a fabricated, already- terminated Process instead of spawning a real subprocess. - Extracting the sync mock's expectation-matching logic into a shared ProcessExecutor::mock_match, wrapping the mock state in a RefCell so it works from execute_async's &self/&mut self receivers. - Setting error_output/capture_output from the mock branch, matching PHP's ProcessExecutorMock::executeAsync sharing doExecute with the sync path; execute_async now takes &mut self for this (safe, since the borrow only needs to live through the synchronous setup, not across the .await). - Turning a strict-mode expectation mismatch from a panic!() into a shirabe_php_shim::RuntimeException Err, mirroring PHPUnit's AssertionFailedError extending \RuntimeException: PHP call sites that catch (\RuntimeException $e) around a mocked git/hg/svn call (e.g. Git::get_mirror_default_branch, GitDriver::supports) treat a mismatch as an ordinary recoverable failure, and now so does the port. The RefMut is dropped before firing an expectation's optional callback so a re-entrant callback doesn't panic on double-borrow. Also fixes two real bugs found while porting test_private_repository_ no_interaction: GitHub::authorize_oauth and GitLab::authorize_oauth checked their domains config via PhpMixed::as_array(), which only matches the Array (map) variant, but github-domains/gitlab-domains default to PhpMixed::List, so the check always returned false and OAuth token lookup was silently skipped. Use the in_array shim instead, matching PHP's in_array() semantics. Also fix Git::run_command's "capture credentials from git remote -v" call, which used the panic- swallowing execute_args wrapper instead of a fallible execute(), so a mock mismatch there couldn't reach get_mirror_default_branch's catch. Un-ignores: - zip_downloader_test::test_system_unzip_only_{good,failed} - zip_downloader_test::test_non_windows_fallback_{good,failed} - event_dispatcher_test::test_dispatcher_outputs_error_on_failed_command - root_package_loader_test::test_feature_branch_pretty_version - version_guesser_test::test_guess_version_reads_and_respects_non_feature_branches_configuration_for_arbitrary_naming{,_regex} - version_guesser_test::test_remote_branches_are_selected - github_driver_test::test_private_repository_no_interaction (also adds the missing #[serial], since it seeds the shared Git::VERSION static that vcs_repository_test::test_load_versions depends on for real) - init_command_test::test_get_git_config, made deterministic by pointing HOME at a throwaway dir with its own .gitconfig instead of depending on the host's global git config Deduplicates the GitVersionGuard/RestoreEnv test-drop-guard idioms into tests/common/test_case.rs instead of reimplementing them per file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/command')
-rw-r--r--crates/shirabe/tests/command/init_command_test.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/crates/shirabe/tests/command/init_command_test.rs b/crates/shirabe/tests/command/init_command_test.rs
index 9c52dddd..57777e35 100644
--- a/crates/shirabe/tests/command/init_command_test.rs
+++ b/crates/shirabe/tests/command/init_command_test.rs
@@ -1,9 +1,10 @@
//! ref: composer/tests/Composer/Test/Command/InitCommandTest.php
-use crate::test_case::{RunOptions, get_application_tester, init_temp_composer};
+use crate::test_case::{RestoreEnv, RunOptions, get_application_tester, init_temp_composer};
use serial_test::serial;
use shirabe::command::init_command::InitCommand;
use shirabe::json::JsonFile;
+use shirabe::util::platform::Platform;
use shirabe_php_shim::{PHP_SERVER, PhpMixed};
use tempfile::TempDir;
@@ -597,13 +598,27 @@ fn test_format_authors() {
assert_eq!(expected, authors[0]);
}
+/// ref: InitCommandTest::testGetGitConfig.
+///
+/// Composer's own CI runs `git config --global user.name/user.email` before the test suite so a
+/// global config is guaranteed to exist; here `HOME` is pointed at a throwaway directory carrying
+/// its own `.gitconfig` with those keys so the test doesn't depend on (or mutate) the real user's
+/// global git config.
#[test]
-#[ignore = "requires the host's global git config to have user.name/user.email set (Composer's \
- own CI runs `git config --global user.name/user.email` before the test suite); \
- fails in environments without that global config"]
+#[serial]
fn test_get_git_config() {
set_up();
+ let home = TempDir::new().unwrap();
+ std::fs::write(
+ home.path().join(".gitconfig"),
+ "[user]\n\tname = Test User\n\temail = test-user@example.com\n",
+ )
+ .unwrap();
+ let original_home = Platform::get_env("HOME");
+ Platform::put_env("HOME", &home.path().to_string_lossy());
+ let _restore_home = RestoreEnv::new("HOME", original_home);
+
let command = InitCommand::new();
let git_config = command.__get_git_config();
assert!(git_config.contains_key("user.name"));