PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/drush/composer/vendor/symfony/console/Tests/Style/SymfonyStyleTest.php

https://bitbucket.org/kbasarab/kbasarab_vim
PHP | 89 lines | 58 code | 14 blank | 17 comment | 0 complexity | 512b094907dc1cd3eb519e519dbc9c96 MD5 | raw file
Possible License(s): MIT
  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\Style;
  11. use PHPUnit_Framework_TestCase;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Style\SymfonyStyle;
  16. use Symfony\Component\Console\Tester\CommandTester;
  17. class SymfonyStyleTest extends PHPUnit_Framework_TestCase
  18. {
  19. /** @var Command */
  20. protected $command;
  21. /** @var CommandTester */
  22. protected $tester;
  23. protected function setUp()
  24. {
  25. $this->command = new Command('sfstyle');
  26. $this->tester = new CommandTester($this->command);
  27. }
  28. protected function tearDown()
  29. {
  30. $this->command = null;
  31. $this->tester = null;
  32. }
  33. /**
  34. * @dataProvider inputCommandToOutputFilesProvider
  35. */
  36. public function testOutputs($inputCommandFilepath, $outputFilepath)
  37. {
  38. $code = require $inputCommandFilepath;
  39. $this->command->setCode($code);
  40. $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
  41. $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
  42. }
  43. public function inputCommandToOutputFilesProvider()
  44. {
  45. $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
  46. return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
  47. }
  48. public function testLongWordsBlockWrapping()
  49. {
  50. $word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
  51. $wordLength = strlen($word);
  52. $maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
  53. $this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) {
  54. $sfStyle = new SymfonyStyleWithForcedLineLength($input, $output);
  55. $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
  56. });
  57. $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
  58. $expectedCount = (int) ceil($wordLength / ($maxLineLength)) + (int) ($wordLength > $maxLineLength - 5);
  59. $this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
  60. }
  61. }
  62. /**
  63. * Use this class in tests to force the line length
  64. * and ensure a consistent output for expectations.
  65. */
  66. class SymfonyStyleWithForcedLineLength extends SymfonyStyle
  67. {
  68. public function __construct(InputInterface $input, OutputInterface $output)
  69. {
  70. parent::__construct($input, $output);
  71. $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength');
  72. $ref->setAccessible(true);
  73. $ref->setValue($this, 120);
  74. }
  75. }