1212use Framework \CLI \CLI ;
1313use Framework \CLI \Streams \Stderr ;
1414use Framework \CLI \Streams \Stdout ;
15+ use Framework \CLI \Styles \BackgroundColor ;
16+ use Framework \CLI \Styles \ForegroundColor ;
17+ use Framework \CLI \Styles \Format ;
1518use PHPUnit \Framework \TestCase ;
1619
1720final class CLITest extends TestCase
@@ -31,7 +34,7 @@ public function testWrite() : void
3134 CLI ::write ('Hello! ' );
3235 self ::assertSame ("Hello! \n" , Stdout::getContents ());
3336 Stdout::reset ();
34- CLI ::write ('Hello! ' , CLI :: FG_RED );
37+ CLI ::write ('Hello! ' , ForegroundColor::red );
3538 self ::assertStringContainsString ("\033[0;31mHello! " , Stdout::getContents ());
3639 Stdout::reset ();
3740 CLI ::write ('Hello! ' , null , null , 2 );
@@ -141,55 +144,61 @@ public function testStyle() : void
141144 self ::assertSame ("foo \033[0m " , CLI ::style ('foo ' ));
142145 self ::assertSame (
143146 "\033[0;31mfoo \033[0m " ,
144- CLI ::style ('foo ' , CLI ::FG_RED )
147+ CLI ::style ('foo ' , ForegroundColor::red)
148+ );
149+ self ::assertSame (
150+ "\033[0;31mfoo \033[0m " ,
151+ CLI ::style ('foo ' , 'red ' )
152+ );
153+ self ::assertSame (
154+ "\033[0;31m \033[44mfoo \033[0m " ,
155+ CLI ::style ('foo ' , ForegroundColor::red, BackgroundColor::blue)
145156 );
146157 self ::assertSame (
147158 "\033[0;31m \033[44mfoo \033[0m " ,
148- CLI ::style ('foo ' , CLI :: FG_RED , CLI :: BG_BLUE )
159+ CLI ::style ('foo ' , ' red ' , ' blue ' )
149160 );
150161 self ::assertSame (
151162 "\033[0;31m \033[44m \033[1m \033[3mfoo \033[0m " ,
152- CLI ::style ('foo ' , CLI ::FG_RED , CLI ::BG_BLUE , [CLI ::FM_BOLD , CLI ::FM_ITALIC ])
163+ CLI ::style ('foo ' , ForegroundColor::red, BackgroundColor::blue, [
164+ Format::bold,
165+ Format::italic,
166+ ])
167+ );
168+ self ::assertSame (
169+ "\033[0;31m \033[44m \033[1m \033[3mfoo \033[0m " ,
170+ CLI ::style ('foo ' , 'red ' , 'blue ' , [
171+ 'bold ' ,
172+ 'italic ' ,
173+ ])
153174 );
154- }
155-
156- public function testConstantsWithStyle () : void
157- {
158- $ class = new \ReflectionClass (CLI ::class);
159- foreach ($ class ->getReflectionConstants (\ReflectionClassConstant::IS_PUBLIC ) as $ constant ) {
160- if (\str_starts_with ($ constant ->getName (), 'BG_ ' )) {
161- self ::assertNotEmpty (CLI ::style ('' , background: $ constant ->getValue ()));
162- continue ;
163- }
164- if (\str_starts_with ($ constant ->getName (), 'FG_ ' )) {
165- self ::assertNotEmpty (CLI ::style ('' , color: $ constant ->getValue ()));
166- continue ;
167- }
168- if (\str_starts_with ($ constant ->getName (), 'FM_ ' )) {
169- self ::assertNotEmpty (CLI ::style ('' , formats: [$ constant ->getValue ()]));
170- }
171- }
172175 }
173176
174177 public function testStyleWithInvalidColor () : void
175178 {
176- $ this ->expectException (\InvalidArgumentException::class);
177- $ this ->expectExceptionMessage ('Invalid color: bar ' );
179+ $ this ->expectException (\ValueError::class);
180+ $ this ->expectExceptionMessage (
181+ '"bar" is not a valid backing value for enum Framework\CLI\Styles\ForegroundColor '
182+ );
178183 CLI ::style ('foo ' , 'bar ' );
179184 }
180185
181186 public function testStyleWithInvalidBackground () : void
182187 {
183- $ this ->expectException (\InvalidArgumentException::class);
184- $ this ->expectExceptionMessage ('Invalid background color: baz ' );
188+ $ this ->expectException (\ValueError::class);
189+ $ this ->expectExceptionMessage (
190+ '"baz" is not a valid backing value for enum Framework\CLI\Styles\BackgroundColor '
191+ );
185192 CLI ::style ('foo ' , null , 'baz ' );
186193 }
187194
188195 public function testStyleWithInvalidFormat () : void
189196 {
190- $ this ->expectException (\InvalidArgumentException::class);
191- $ this ->expectExceptionMessage ('Invalid format: bar ' );
192- CLI ::style ('foo ' , null , null , [CLI ::FM_BOLD , 'bar ' ]);
197+ $ this ->expectException (\ValueError::class);
198+ $ this ->expectExceptionMessage (
199+ '"bar" is not a valid backing value for enum Framework\CLI\Styles\Format '
200+ );
201+ CLI ::style ('foo ' , null , null , [Format::bold, 'bar ' ]);
193202 }
194203
195204 public function testBox () : void
0 commit comments