From f3d60c7836da0d50d59a22cfd6e4692e3dc75581 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 05:59:40 +0900 Subject: test(console): cover the dev build warning branch The deadline is a constant baked in at build time, so PHP's define() of COMPOSER_DEV_WARNING_TIME cannot make Application take that branch. Application now holds the deadline in a field that __set_dev_warning_time overrides, letting testDevWarning run instead of staying ignored. The define() shim, whose only caller was that test, goes away with it. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/console/application.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'crates/shirabe/src/console') diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 16a67b72..bf1f3575 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -131,6 +131,9 @@ pub struct Application { disable_scripts_by_default: bool, /// Store the initial working directory at startup time initial_working_directory: Option, + /// For testing only: see [__set_dev_warning_time](Application::__set_dev_warning_time) for + /// details. + dev_warning_time: Option, /// Self-reference used to hand commands their owning application (PHP's `$command->setApplication($this)`). /// Set by `new_shared`; the run flow threads the upgraded `Rc` so command callbacks never /// re-borrow the application while it is already borrowed. @@ -193,6 +196,7 @@ impl Application { disable_plugins_by_default: false, disable_scripts_by_default: false, initial_working_directory, + dev_warning_time: composer::COMPOSER_DEV_WARNING_TIME, me: std::rc::Weak::new(), }; if defined("SIGINT") && SignalRegistry::is_supported() { @@ -2281,7 +2285,8 @@ impl ApplicationHandle { io.write_error("Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug"); } - if let Some(dev_warning_time) = composer::COMPOSER_DEV_WARNING_TIME + let dev_warning_time = application.borrow().dev_warning_time; + if let Some(dev_warning_time) = dev_warning_time && command_name.as_deref() != Some("self-update") && command_name.as_deref() != Some("selfupdate") && time() > dev_warning_time @@ -2570,6 +2575,12 @@ impl ApplicationHandle { self.0.borrow_mut().set_catch_exceptions(boolean); } + /// For testing only: simulating dynamically define COMPOSER_DEV_WARNING_TIME constant via + /// `define()` in PHP. + pub fn __set_dev_warning_time(&self, dev_warning_time: Option) { + self.0.borrow_mut().dev_warning_time = dev_warning_time; + } + /// For testing only: exposes the application as a Symfony base-application handle, the way /// console commands receive it via `getApplication()`, so tests can build an /// `ApplicationDescription` over it. -- cgit v1.3.1-4-g156e