aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-24 20:23:18 +0900
committernsfisis <nsfisis@gmail.com>2026-07-24 20:23:18 +0900
commit70198f0c1e67594549193413fb8e86b1879dc41d (patch)
tree58f7cdf7c0529bf2477855c93879ca50a9f38080
parenta0f4c7518ab09de8ebe166d9d3b4d15149a22439 (diff)
downloadphp-shirabe-70198f0c1e67594549193413fb8e86b1879dc41d.tar.gz
php-shirabe-70198f0c1e67594549193413fb8e86b1879dc41d.tar.zst
php-shirabe-70198f0c1e67594549193413fb8e86b1879dc41d.zip
fix(installer-test): catch exceptions thrown during composer construction
PHPUnit's expectException/expectExceptionMessage wrap the whole rest of InstallerTest::doTestIntegration, so a fixture's expected exception can legitimately come from FactoryMock::create() itself (root package construction), not just the later install/update run. The Rust port only checked for that at one point, after the run, and unconditionally unwrapped Factory::__create_mock's result — so a fixture like install-self-from-root.test (root package requiring itself, which throws during root package construction) panicked on that unwrap instead of being caught and compared against the expected message. Capture the construction Result and, when an exception was expected, run the same normalize/contains/assert check the later block already uses before returning early, matching PHPUnit's behavior of running no further test-method code once the expected exception has fired.
-rw-r--r--crates/shirabe/tests/installer_test.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/crates/shirabe/tests/installer_test.rs b/crates/shirabe/tests/installer_test.rs
index 7a581a00..e4fe681c 100644
--- a/crates/shirabe/tests/installer_test.rs
+++ b/crates/shirabe/tests/installer_test.rs
@@ -856,13 +856,28 @@ fn do_test_integration(case: &IntegrationCase, expect_output: Option<&str>) {
.as_array()
.cloned()
.unwrap_or_default();
- let composer = Factory::__create_mock(
+ let composer_result = Factory::__create_mock(
io.clone(),
Some(LocalConfigInput::Data(composer_data)),
DisablePlugins::None,
false,
- )
- .unwrap();
+ );
+ // PHP's PHPUnit::expectException wraps the whole rest of the test method, so an exception
+ // expected from the fixture can come from composer construction itself, not just the later
+ // install/update run; check for that here since Rust has no equivalent ambient wrapper.
+ if is_exception && let Err(e) = &composer_result {
+ let normalized = case.expect.replace('\n', shirabe_php_shim::PHP_EOL);
+ let normalized = normalized.trim_end();
+ let err = format!("{}", e);
+ assert!(
+ err.contains(normalized),
+ "expected exception message containing:\n{}\n--- got ---\n{}",
+ normalized,
+ err
+ );
+ return;
+ }
+ let composer = composer_result.unwrap();
// installed.json mock: a real JsonFile over a temp file holding $installed, wrapped in the
// no-op InstalledFilesystemRepositoryMock.
@@ -1411,7 +1426,7 @@ pool_optimizer_test! {
pool_optimizer_install_prefers_repos_over_package_versions => "install-prefers-repos-over-package-versions.test";
pool_optimizer_install_reference => "install-reference.test";
pool_optimizer_install_security_advisory_matching_dependency => "install-security-advisory-matching-dependency.test";
- pool_optimizer_install_self_from_root => "install-self-from-root.test", ignore = "TODO(phase-d): known-failing fixture under COMPOSER_POOL_OPTIMIZER=1";
+ pool_optimizer_install_self_from_root => "install-self-from-root.test";
pool_optimizer_install_simple => "install-simple.test";
pool_optimizer_install_without_lock => "install-without-lock.test";
pool_optimizer_load_replaced_package_if_replacer_dropped => "load-replaced-package-if-replacer-dropped.test";
@@ -1601,7 +1616,7 @@ raw_pool_test! {
raw_pool_install_prefers_repos_over_package_versions => "install-prefers-repos-over-package-versions.test";
raw_pool_install_reference => "install-reference.test";
raw_pool_install_security_advisory_matching_dependency => "install-security-advisory-matching-dependency.test";
- raw_pool_install_self_from_root => "install-self-from-root.test", ignore = "TODO(phase-d): known-failing fixture under COMPOSER_POOL_OPTIMIZER=0";
+ raw_pool_install_self_from_root => "install-self-from-root.test";
raw_pool_install_simple => "install-simple.test";
raw_pool_install_without_lock => "install-without-lock.test";
raw_pool_load_replaced_package_if_replacer_dropped => "load-replaced-package-if-replacer-dropped.test";