ee9b09f8f97ed50545716e8caef5cdbf02a01e33
[yaffs-website] / vendor / symfony / console / Tests / Style / SymfonyStyleTest.php
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\Style;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Command\Command;
16 use Symfony\Component\Console\Input\InputInterface;
17 use Symfony\Component\Console\Output\OutputInterface;
18 use Symfony\Component\Console\Style\SymfonyStyle;
19 use Symfony\Component\Console\Tester\CommandTester;
20
21 class SymfonyStyleTest extends TestCase
22 {
23     /** @var Command */
24     protected $command;
25     /** @var CommandTester */
26     protected $tester;
27
28     protected function setUp()
29     {
30         $this->command = new Command('sfstyle');
31         $this->tester = new CommandTester($this->command);
32     }
33
34     protected function tearDown()
35     {
36         $this->command = null;
37         $this->tester = null;
38     }
39
40     /**
41      * @dataProvider inputCommandToOutputFilesProvider
42      */
43     public function testOutputs($inputCommandFilepath, $outputFilepath)
44     {
45         $code = require $inputCommandFilepath;
46         $this->command->setCode($code);
47         $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
48         $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
49     }
50
51     public function inputCommandToOutputFilesProvider()
52     {
53         $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
54
55         return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
56     }
57 }
58
59 /**
60  * Use this class in tests to force the line length
61  * and ensure a consistent output for expectations.
62  */
63 class SymfonyStyleWithForcedLineLength extends SymfonyStyle
64 {
65     public function __construct(InputInterface $input, OutputInterface $output)
66     {
67         parent::__construct($input, $output);
68
69         $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength');
70         $ref->setAccessible(true);
71         $ref->setValue($this, 120);
72     }
73 }