TYPO3  7.6
SymfonyStyleTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Symfony\Component\Console\Tests\Style;
4 
5 use PHPUnit_Framework_TestCase;
11 
12 class SymfonyStyleTest extends PHPUnit_Framework_TestCase
13 {
15  protected $command;
17  protected $tester;
18 
19  protected function setUp()
20  {
21  $this->command = new Command('sfstyle');
22  $this->tester = new CommandTester($this->command);
23  }
24 
25  protected function tearDown()
26  {
27  $this->command = null;
28  $this->tester = null;
29  }
30 
34  public function testOutputs($inputCommandFilepath, $outputFilepath)
35  {
36  $code = require $inputCommandFilepath;
37  $this->command->setCode($code);
38  $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
39  $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
40  }
41 
43  {
44  $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
45 
46  return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
47  }
48 
49  public function testLongWordsBlockWrapping()
50  {
51  $word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
52  $wordLength = strlen($word);
53  $maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
54 
55  $this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) {
56  $sfStyle = new SymfonyStyle($input, $output);
57  $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
58  });
59 
60  $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
61  $expectedCount = (int) ceil($wordLength / ($maxLineLength)) + (int) ($wordLength > $maxLineLength - 5);
62  $this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
63  }
64 }