diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 05:59:40 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 05:59:40 +0900 |
| commit | f3d60c7836da0d50d59a22cfd6e4692e3dc75581 (patch) | |
| tree | eafdc0bdd8a05b11e5a511d7ab4bb48a5e42609e | |
| parent | a6fc2831562fa83b8f20a3b8285b87102c1775d8 (diff) | |
| download | php-shirabe-f3d60c7836da0d50d59a22cfd6e4692e3dc75581.tar.gz php-shirabe-f3d60c7836da0d50d59a22cfd6e4692e3dc75581.tar.zst php-shirabe-f3d60c7836da0d50d59a22cfd6e4692e3dc75581.zip | |
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) <noreply@anthropic.com>
| -rw-r--r-- | crates/shirabe-php-shim/src/runtime.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 13 | ||||
| -rw-r--r-- | crates/shirabe/tests/application_test.rs | 7 |
3 files changed, 14 insertions, 12 deletions
diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs index 05396b3b..c00c8f51 100644 --- a/crates/shirabe-php-shim/src/runtime.rs +++ b/crates/shirabe-php-shim/src/runtime.rs @@ -49,12 +49,6 @@ pub fn constant(_name: &str) -> PhpMixed { todo!() } -pub fn define(_constant_name: &str, _value: PhpMixed) -> bool { - // TODO(php-runtime): defining a constant at runtime needs the same registry `constant` and - // `defined` would read from; the shim has none. - todo!() -} - // Models the constants defined in a standard modern PHP CLI environment on a // non-Windows platform with the common extensions loaded (curl, openssl, json). // Windows-only, HHVM and Composer-bootstrap constants are reported undefined. 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<String>, + /// For testing only: see [__set_dev_warning_time](Application::__set_dev_warning_time) for + /// details. + dev_warning_time: Option<i64>, /// 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("<warning>Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug</warning>"); } - 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<i64>) { + 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. diff --git a/crates/shirabe/tests/application_test.rs b/crates/shirabe/tests/application_test.rs index 794a4352..4e8a0f05 100644 --- a/crates/shirabe/tests/application_test.rs +++ b/crates/shirabe/tests/application_test.rs @@ -17,7 +17,7 @@ use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::buffered_output::BufferedOutput; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; -use shirabe_php_shim::{PHP_EOL, PHP_SERVER, PhpMixed, define, defined, time}; +use shirabe_php_shim::{PHP_EOL, PHP_SERVER, PhpMixed, time}; fn set_up() { Platform::put_env("COMPOSER_DISABLE_XDEBUG_WARN", "1"); @@ -35,7 +35,6 @@ impl Drop for TearDown { } } -#[ignore = "the dev warning deadline is a Rust constant baked in by build.rs, so a runtime define() of COMPOSER_DEV_WARNING_TIME cannot make Application take the warning branch"] #[test] fn test_dev_warning() { let _tear_down = TearDown; @@ -43,9 +42,7 @@ fn test_dev_warning() { let application = ApplicationHandle::new("Composer".to_string(), "".to_string()).unwrap(); - if !defined("COMPOSER_DEV_WARNING_TIME") { - define("COMPOSER_DEV_WARNING_TIME", PhpMixed::Int(time() - 1)); - } + application.__set_dev_warning_time(Some(time() - 1)); let output = std::rc::Rc::new(std::cell::RefCell::new(BufferedOutput::new( None, false, None, |
