From a75ac1d98babac2c13e0602d9818c7bed7ea9532 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Wed, 6 Mar 2024 17:04:33 +1300 Subject: [PATCH] ENH Add lightweight test override for Environment::isCli() --- src/Core/Environment.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Core/Environment.php b/src/Core/Environment.php index a6b0fc7ef..aa39a0cc0 100644 --- a/src/Core/Environment.php +++ b/src/Core/Environment.php @@ -35,6 +35,13 @@ class Environment */ protected static $env = []; + /** + * Used by unit tests to override `isCli()` + * This is not config. Use reflection to change the value + * @internal + */ + private static ?bool $isCliOverride = null; + /** * Extract env vars prior to modification * @@ -251,6 +258,9 @@ class Environment */ public static function isCli() { + if (self::$isCliOverride !== null) { + return self::$isCliOverride; + } return in_array(strtolower(php_sapi_name() ?? ''), ['cli', 'phpdbg']); } }