|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Console\Tests\Formatter; |
| 13 | + |
| 14 | +use Symfony\Component\Console\Formatter\OutputFormatterStyleStack; |
| 15 | +use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
| 16 | + |
| 17 | +class OutputFormatterStyleStackTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + public function testPush() |
| 20 | + { |
| 21 | + $stack = new OutputFormatterStyleStack(); |
| 22 | + $stack->push($s1 = new OutputFormatterStyle('white', 'black')); |
| 23 | + $stack->push($s2 = new OutputFormatterStyle('yellow', 'blue')); |
| 24 | + |
| 25 | + $this->assertEquals($s2, $stack->getCurrent()); |
| 26 | + |
| 27 | + $stack->push($s3 = new OutputFormatterStyle('green', 'red')); |
| 28 | + |
| 29 | + $this->assertEquals($s3, $stack->getCurrent()); |
| 30 | + } |
| 31 | + |
| 32 | + public function testPop() |
| 33 | + { |
| 34 | + $stack = new OutputFormatterStyleStack(); |
| 35 | + $stack->push($s1 = new OutputFormatterStyle('white', 'black')); |
| 36 | + $stack->push($s2 = new OutputFormatterStyle('yellow', 'blue')); |
| 37 | + |
| 38 | + $this->assertEquals($s2, $stack->pop()); |
| 39 | + $this->assertEquals($s1, $stack->pop()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testPopEmpty() |
| 43 | + { |
| 44 | + $stack = new OutputFormatterStyleStack(); |
| 45 | + $style = new OutputFormatterStyle(); |
| 46 | + |
| 47 | + $this->assertEquals($style, $stack->pop()); |
| 48 | + } |
| 49 | + |
| 50 | + public function testPopNotLast() |
| 51 | + { |
| 52 | + $stack = new OutputFormatterStyleStack(); |
| 53 | + $stack->push($s1 = new OutputFormatterStyle('white', 'black')); |
| 54 | + $stack->push($s2 = new OutputFormatterStyle('yellow', 'blue')); |
| 55 | + $stack->push($s3 = new OutputFormatterStyle('green', 'red')); |
| 56 | + |
| 57 | + $this->assertEquals($s2, $stack->pop($s2)); |
| 58 | + $this->assertEquals($s1, $stack->pop()); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @expectedException InvalidArgumentException |
| 63 | + */ |
| 64 | + public function testInvalidPop() |
| 65 | + { |
| 66 | + $stack = new OutputFormatterStyleStack(); |
| 67 | + $stack->push(new OutputFormatterStyle('white', 'black')); |
| 68 | + $stack->pop(new OutputFormatterStyle('yellow', 'blue')); |
| 69 | + } |
| 70 | +} |
0 commit comments