4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Tests\Style;
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;
21 class SymfonyStyleTest extends TestCase
25 /** @var CommandTester */
28 protected function setUp()
30 $this->command = new Command('sfstyle');
31 $this->tester = new CommandTester($this->command);
34 protected function tearDown()
36 $this->command = null;
41 * @dataProvider inputCommandToOutputFilesProvider
43 public function testOutputs($inputCommandFilepath, $outputFilepath)
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));
51 public function inputCommandToOutputFilesProvider()
53 $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
55 return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
60 * Use this class in tests to force the line length
61 * and ensure a consistent output for expectations.
63 class SymfonyStyleWithForcedLineLength extends SymfonyStyle
65 public function __construct(InputInterface $input, OutputInterface $output)
67 parent::__construct($input, $output);
69 $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength');
70 $ref->setAccessible(true);
71 $ref->setValue($this, 120);