OutputFormatterStyleStackTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Component\Console\Tests\Formatter;
  11. use Symfony\Component\Console\Formatter\OutputFormatterStyleStack;
  12. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  13. class OutputFormatterStyleStackTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testPush()
  16. {
  17. $stack = new OutputFormatterStyleStack();
  18. $stack->push($s1 = new OutputFormatterStyle('white', 'black'));
  19. $stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
  20. $this->assertEquals($s2, $stack->getCurrent());
  21. $stack->push($s3 = new OutputFormatterStyle('green', 'red'));
  22. $this->assertEquals($s3, $stack->getCurrent());
  23. }
  24. public function testPop()
  25. {
  26. $stack = new OutputFormatterStyleStack();
  27. $stack->push($s1 = new OutputFormatterStyle('white', 'black'));
  28. $stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
  29. $this->assertEquals($s2, $stack->pop());
  30. $this->assertEquals($s1, $stack->pop());
  31. }
  32. public function testPopEmpty()
  33. {
  34. $stack = new OutputFormatterStyleStack();
  35. $style = new OutputFormatterStyle();
  36. $this->assertEquals($style, $stack->pop());
  37. }
  38. public function testPopNotLast()
  39. {
  40. $stack = new OutputFormatterStyleStack();
  41. $stack->push($s1 = new OutputFormatterStyle('white', 'black'));
  42. $stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
  43. $stack->push($s3 = new OutputFormatterStyle('green', 'red'));
  44. $this->assertEquals($s2, $stack->pop($s2));
  45. $this->assertEquals($s1, $stack->pop());
  46. }
  47. /**
  48. * @expectedException \InvalidArgumentException
  49. */
  50. public function testInvalidPop()
  51. {
  52. $stack = new OutputFormatterStyleStack();
  53. $stack->push(new OutputFormatterStyle('white', 'black'));
  54. $stack->pop(new OutputFormatterStyle('yellow', 'blue'));
  55. }
  56. }