OutputFormatterStyleStackTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }