ENH Add lightweight test override for Environment::isCli()

This commit is contained in:
Guy Sartorelli 2024-03-06 17:04:33 +13:00
parent 054c2389c9
commit a75ac1d98b
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
1 changed files with 10 additions and 0 deletions

View File

@ -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']);
}
}