13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \Console \Color ;
16
+ use Symfony \Component \Console \Exception \InvalidArgumentException ;
16
17
17
18
class ColorTest extends TestCase
18
19
{
@@ -42,6 +43,9 @@ public function testTrueColors()
42
43
43
44
$ color = new Color ('#ffffff ' , '#000000 ' );
44
45
$ this ->assertSame ("\033[38;2;255;255;255;48;2;0;0;0m \033[39;49m " , $ color ->apply (' ' ));
46
+
47
+ $ color = new Color ('rgb(255, 255, 255) ' , 'rgb(0, 0, 0) ' );
48
+ $ this ->assertSame ("\033[38;2;255;255;255;48;2;0;0;0m \033[39;49m " , $ color ->apply (' ' ));
45
49
}
46
50
47
51
public function testDegradedTrueColors ()
@@ -59,4 +63,32 @@ public function testDegradedTrueColors()
59
63
putenv ('COLORTERM= ' .$ colorterm );
60
64
}
61
65
}
66
+
67
+ /**
68
+ * @dataProvider provideMalformedRgbStrings
69
+ */
70
+ public function testMalformedRgbString (string $ color , string $ exceptionMessage )
71
+ {
72
+ $ this ->expectException (InvalidArgumentException::class);
73
+ $ this ->expectExceptionMessage ($ exceptionMessage );
74
+
75
+ new Color ($ color );
76
+ }
77
+
78
+ public function provideMalformedRgbStrings (): \Generator
79
+ {
80
+ yield ['rgb() ' , 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb()". ' ];
81
+
82
+ yield ['rgb(0, 0) ' , 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(0, 0)". ' ];
83
+
84
+ yield ['rgb(0, 0, 0, 0) ' , 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(0, 0, 0, 0)". ' ];
85
+
86
+ yield ['rgb(-1, 0, 0) ' , 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(-1, 0, 0)". ' ];
87
+
88
+ yield ['rgb(invalid, 0, 0) ' , 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(invalid, 0, 0)". ' ];
89
+
90
+ yield ['rgb(256, 0, 0) ' , 'Invalid color component; value should be between 0 and 255, got 256. ' ];
91
+
92
+ yield ['rgb(0, 0, 0 ' , 'Invalid RGB functional notation; should be of the form "rgb(r, g, b)", got "rgb(0, 0, 0". ' ];
93
+ }
62
94
}
0 commit comments