CLI::style() returns early when supportsAnsi() is false (src/CLI.php:206-208), before the ForegroundColor::from() / BackgroundColor::from() / Format::from() calls that validate the arguments. The documented @throws ValueError therefore depends on the terminal:
CLI::style('foo', 'not-a-color');
// ANSI terminal: ValueError
// piped / --no-ansi: returns 'foo', no error
That is the worst shape for this kind of check: a typo in a color name passes in CI or when output is redirected and only blows up on a developer machine, or the other way round. It is also why testStyleWithInvalidColor and its two siblings fail when the test process has no ANSI capable STDOUT (see the test portability issue).
Expected: validate and resolve the enums first, then decide whether to emit the codes. Same for write(), which forwards to style().
CLI::style()returns early whensupportsAnsi()is false (src/CLI.php:206-208), before theForegroundColor::from()/BackgroundColor::from()/Format::from()calls that validate the arguments. The documented@throws ValueErrortherefore depends on the terminal:That is the worst shape for this kind of check: a typo in a color name passes in CI or when output is redirected and only blows up on a developer machine, or the other way round. It is also why
testStyleWithInvalidColorand its two siblings fail when the test process has no ANSI capable STDOUT (see the test portability issue).Expected: validate and resolve the enums first, then decide whether to emit the codes. Same for
write(), which forwards tostyle().