|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Console\Tests\Formatter;
|
13 | 13 |
|
| 14 | +use Symfony\Bridge\PhpUnit\ErrorAssert; |
14 | 15 | use Symfony\Component\Console\Formatter\OutputFormatter;
|
15 | 16 | use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
16 | 17 |
|
@@ -152,6 +153,72 @@ public function testInlineStyle()
|
152 | 153 | $this->assertEquals("\033[34;41msome text\033[39;49m", $formatter->format('<fg=blue;bg=red>some text</fg=blue;bg=red>'));
|
153 | 154 | }
|
154 | 155 |
|
| 156 | + /** |
| 157 | + * @param string $tag |
| 158 | + * @param string|null $expected |
| 159 | + * @param string|null $input |
| 160 | + * |
| 161 | + * @dataProvider provideInlineStyleOptionsCases |
| 162 | + */ |
| 163 | + public function testInlineStyleOptions($tag, $expected = null, $input = null) |
| 164 | + { |
| 165 | + $styleString = substr($tag, 1, -1); |
| 166 | + $formatter = new OutputFormatter(true); |
| 167 | + $method = new \ReflectionMethod($formatter, 'createStyleFromString'); |
| 168 | + $method->setAccessible(true); |
| 169 | + $result = $method->invoke($formatter, $styleString); |
| 170 | + if (null === $expected) { |
| 171 | + $this->assertFalse($result); |
| 172 | + $expected = $tag.$input.'</'.$styleString.'>'; |
| 173 | + $this->assertSame($expected, $formatter->format($expected)); |
| 174 | + } else { |
| 175 | + /* @var OutputFormatterStyle $result */ |
| 176 | + $this->assertInstanceOf(OutputFormatterStyle::class, $result); |
| 177 | + $this->assertSame($expected, $formatter->format($tag.$input.'</>')); |
| 178 | + $this->assertSame($expected, $formatter->format($tag.$input.'</'.$styleString.'>')); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + public function provideInlineStyleOptionsCases() |
| 183 | + { |
| 184 | + return array( |
| 185 | + array('<unknown=_unknown_>'), |
| 186 | + array('<unknown=_unknown_;a=1;b>'), |
| 187 | + array('<fg=green;>', "\033[32m[test]\033[39m", '[test]'), |
| 188 | + array('<fg=green;bg=blue;>', "\033[32;44ma\033[39;49m", 'a'), |
| 189 | + array('<fg=green;options=bold>', "\033[32;1mb\033[39;22m", 'b'), |
| 190 | + array('<fg=green;options=reverse;>', "\033[32;7m<a>\033[39;27m", '<a>'), |
| 191 | + array('<fg=green;options=bold,underscore>', "\033[32;1;4mz\033[39;22;24m", 'z'), |
| 192 | + array('<fg=green;options=bold,underscore,reverse;>', "\033[32;1;4;7md\033[39;22;24;27m", 'd'), |
| 193 | + ); |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * @group legacy |
| 198 | + * @dataProvider provideInlineStyleTagsWithUnknownOptions |
| 199 | + * @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered |
| 200 | + */ |
| 201 | + public function testInlineStyleOptionsUnknownAreDeprecated($tag, $option) |
| 202 | + { |
| 203 | + ErrorAssert::assertDeprecationsAreTriggered( |
| 204 | + array(sprintf('Unknown style options are deprecated since version 3.2 and will be removed in 4.0. Exception "Invalid option specified: "%s". Expected one of (bold, underscore, blink, reverse, conceal)".', $option)), |
| 205 | + function () use ($tag) { |
| 206 | + $formatter = new OutputFormatter(true); |
| 207 | + $formatter->format($tag); |
| 208 | + } |
| 209 | + ); |
| 210 | + } |
| 211 | + |
| 212 | + public function provideInlineStyleTagsWithUnknownOptions() |
| 213 | + { |
| 214 | + return array( |
| 215 | + array('<options=abc;>', 'abc'), |
| 216 | + array('<options=abc,def;>', 'abc'), |
| 217 | + array('<fg=green;options=xyz;>', 'xyz'), |
| 218 | + array('<fg=green;options=efg,abc>', 'efg'), |
| 219 | + ); |
| 220 | + } |
| 221 | + |
155 | 222 | public function testNonStyleTag()
|
156 | 223 | {
|
157 | 224 | $formatter = new OutputFormatter(true);
|
|
0 commit comments