OutputFormatterStyleStackTest.php 2.1 KB

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