diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-02 17:33:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-02 17:33:04 +0900 |
| commit | 48af92c807a7cd1df54c2b1df5dba508aefc6b6e (patch) | |
| tree | ab53e0e1d1556306d31d8de6019dd5745398a935 /crates/shirabe/tests | |
| parent | 87378b434257afe0d4ffb4093eafa6282e0d2ec8 (diff) | |
| download | php-shirabe-48af92c807a7cd1df54c2b1df5dba508aefc6b6e.tar.gz php-shirabe-48af92c807a7cd1df54c2b1df5dba508aefc6b6e.tar.zst php-shirabe-48af92c807a7cd1df54c2b1df5dba508aefc6b6e.zip | |
test(bootstrap): port the remaining env setup from tests/bootstrap.php
Add NO_COLOR=1, the COMPOSER/COMPOSER_VENDOR_DIR/COMPOSER_BIN_DIR clears and
the timezone normalization, and make bootstrap() Once-guarded so additional
call sites stay safe. Wiring it into every test binary still needs a libtest
setup hook (ctor crate or fixture-level calls), recorded in the TODO.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests')
| -rw-r--r-- | crates/shirabe/tests/common/bootstrap.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/crates/shirabe/tests/common/bootstrap.rs b/crates/shirabe/tests/common/bootstrap.rs index 6e7cd32c..8b2a8aa0 100644 --- a/crates/shirabe/tests/common/bootstrap.rs +++ b/crates/shirabe/tests/common/bootstrap.rs @@ -10,10 +10,31 @@ use shirabe::util::platform::Platform; /// /// TODO(phase-d): this is only wired into `get_application_tester()` (used by the `command` test /// binary) rather than into every test binary's `main.rs`, unlike PHPUnit's bootstrap which -/// covers the whole suite unconditionally. Call this from a shared entry point across all test -/// binaries once one exists. +/// covers the whole suite unconditionally. Rust's libtest has no per-binary setup hook, so a true +/// equivalent needs either the `ctor` crate (new dependency, user decision) or wiring a call into +/// every shared fixture constructor. pub fn bootstrap() { - Platform::put_env("COMPOSER_TESTS_ARE_RUNNING", "1"); + static ONCE: std::sync::Once = std::sync::Once::new(); + ONCE.call_once(|| { + // PHP: error_reporting(E_ALL) has no counterpart here. - // TODO(phase-d): port remaining bootstrap processes. + // PHP: date_default_timezone_set(@date_default_timezone_get()); + shirabe_php_shim::date_default_timezone_set(&shirabe_php_shim::date_default_timezone_get()); + + // PHP: require src/bootstrap.php and refresh vendor/composer/InstalledVersions.php. + // TODO(phase-d): port remaining bootstrap processes (the src/bootstrap.php include and + // the InstalledVersions refresh are PHP autoload mechanics with no Rust counterpart yet). + + Platform::put_env("COMPOSER_TESTS_ARE_RUNNING", "1"); + + // ensure Windows color support detection does not attempt to use colors + // as this is dependent on env vars and not actual stream capabilities, see + // https://github.com/composer/composer/issues/11598 + Platform::put_env("NO_COLOR", "1"); + + // symfony/phpunit-bridge sets some default env vars which we do not need polluting the test env + Platform::clear_env("COMPOSER"); + Platform::clear_env("COMPOSER_VENDOR_DIR"); + Platform::clear_env("COMPOSER_BIN_DIR"); + }); } |
