OutputFormatterStyleTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Console\Formatter;
  11. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  12. class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testConstructor()
  15. {
  16. $style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore'));
  17. $this->assertEquals("\033[32;40;1;4m", $style->getBeginStyle());
  18. $this->assertEquals("\033[0m", $style->getEndStyle());
  19. $style = new OutputFormatterStyle('red', null, array('blink'));
  20. $this->assertEquals("\033[31;5m", $style->getBeginStyle());
  21. $this->assertEquals("\033[0m", $style->getEndStyle());
  22. $style = new OutputFormatterStyle(null, 'white');
  23. $this->assertEquals("\033[47m", $style->getBeginStyle());
  24. $this->assertEquals("\033[0m", $style->getEndStyle());
  25. }
  26. public function testForeground()
  27. {
  28. $style = new OutputFormatterStyle();
  29. $style->setForeground('black');
  30. $this->assertEquals("\033[30m", $style->getBeginStyle());
  31. $this->assertEquals("\033[0m", $style->getEndStyle());
  32. $style->setForeground('blue');
  33. $this->assertEquals("\033[34m", $style->getBeginStyle());
  34. $this->assertEquals("\033[0m", $style->getEndStyle());
  35. $this->setExpectedException('InvalidArgumentException');
  36. $style->setForeground('undefined-color');
  37. }
  38. public function testBackground()
  39. {
  40. $style = new OutputFormatterStyle();
  41. $style->setBackground('black');
  42. $this->assertEquals("\033[40m", $style->getBeginStyle());
  43. $this->assertEquals("\033[0m", $style->getEndStyle());
  44. $style->setBackground('yellow');
  45. $this->assertEquals("\033[43m", $style->getBeginStyle());
  46. $this->setExpectedException('InvalidArgumentException');
  47. $style->setBackground('undefined-color');
  48. }
  49. public function testOptions()
  50. {
  51. $style = new OutputFormatterStyle();
  52. $style->setOptions(array('reverse', 'conceal'));
  53. $this->assertEquals("\033[7;8m", $style->getBeginStyle());
  54. $style->setOption('bold');
  55. $this->assertEquals("\033[7;8;1m", $style->getBeginStyle());
  56. $style->unsetOption('reverse');
  57. $this->assertEquals("\033[8;1m", $style->getBeginStyle());
  58. $style->setOption('bold');
  59. $this->assertEquals("\033[8;1m", $style->getBeginStyle());
  60. $style->setOptions(array('bold'));
  61. $this->assertEquals("\033[1m", $style->getBeginStyle());
  62. }
  63. }