Skip to content

Commit

Permalink
ENH Add lightweight test override for Environment::isCli()
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Mar 18, 2024
1 parent 054c238 commit a75ac1d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Core/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -251,6 +258,9 @@ public static function hasEnv(string $name): bool
*/
public static function isCli()
{
if (self::$isCliOverride !== null) {
return self::$isCliOverride;
}
return in_array(strtolower(php_sapi_name() ?? ''), ['cli', 'phpdbg']);
}
}

0 comments on commit a75ac1d

Please sign in to comment.