From 85e5060fa136e39d4de491041e49fe4aeb9207f3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 20 Jun 2016 07:04:25 +0200 Subject: [PATCH] [Console] simplified tests --- .../Style/SymfonyStyle/command/command_0.php | 4 ++-- .../Style/SymfonyStyle/command/command_1.php | 4 ++-- .../Style/SymfonyStyle/command/command_10.php | 4 ++-- .../Style/SymfonyStyle/command/command_11.php | 4 ++-- .../Style/SymfonyStyle/command/command_12.php | 4 ++-- .../Style/SymfonyStyle/command/command_2.php | 4 ++-- .../Style/SymfonyStyle/command/command_3.php | 4 ++-- .../Style/SymfonyStyle/command/command_4.php | 4 ++-- .../Style/SymfonyStyle/command/command_5.php | 4 ++-- .../Style/SymfonyStyle/command/command_6.php | 4 ++-- .../Style/SymfonyStyle/command/command_7.php | 4 ++-- .../Style/SymfonyStyle/command/command_8.php | 4 ++-- .../Style/SymfonyStyle/command/command_9.php | 4 ++-- .../command/interactive_command_1.php | 4 ++-- .../Console/Tests/Style/SymfonyStyleTest.php | 19 +------------------ 15 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php index 996fafb989..8fe7c07712 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php @@ -2,10 +2,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line at start when using block element return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->caution('Lorem ipsum dolor sit amet'); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php index 6634cd5690..e5c700d60e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line between titles and blocks return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->title('Title'); $output->warning('Lorem ipsum dolor sit amet'); $output->title('Title'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php index 4120df9cb6..3111873ddd 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_10.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure that all lines are aligned to the begin of the first line in a very long line block return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->block( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', 'CUSTOM', diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php index 678afea5d7..3ed897def4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_11.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; // ensure long words are properly wrapped in blocks return function (InputInterface $input, OutputInterface $output) { $word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon'; - $sfStyle = new SymfonyStyleWithForcedLineLength($input, $output); + $sfStyle = new SymfonyStyle($input, $output); $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' ยง ', false); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php index 4386e56de2..8c458ae764 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; // ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->comment( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum' ); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php index 6004e3d6c2..791b626f24 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line between blocks return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->warning('Warning'); $output->caution('Caution'); $output->error('Error'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php index c7a08f138d..99253a6c08 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line between two titles return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->title('First title'); $output->title('Second title'); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php index afea70c7aa..0c5d3fb26c 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has single blank line after any text and a title return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->write('Lorem ipsum dolor sit amet'); $output->title('First title'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php index d2c68a9e73..92f358204c 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has proper line ending before outputing a text block like with SymfonyStyle::listing() or SymfonyStyle::text() return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->writeln('Lorem ipsum dolor sit amet'); $output->listing(array( diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php index f1d7990544..8031ec9c30 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure has proper blank line after text block when using a block like with SymfonyStyle::success return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->listing(array( 'Lorem ipsum dolor sit amet', diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php index cbfea734b4..203eb5b12e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure questions do not output anything when input is non-interactive return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->title('Title'); $output->askHidden('Hidden question'); $output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php index 0244fd2725..922ef1f9d5 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_8.php @@ -2,7 +2,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Helper\TableCell; //Ensure formatting tables when using multiple headers with TableCell @@ -21,6 +21,6 @@ return function (InputInterface $input, OutputInterface $output) { array('978-0804169127', 'Divine Comedy'), ); - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->table($headers, $rows); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php index 6420730fd6..57afdf06b4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_9.php @@ -2,10 +2,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure that all lines are aligned to the begin of the first line in a multi-line block return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $output->block(array('Custom block', 'Second custom block line'), 'CUSTOM', 'fg=white;bg=green', 'X ', true); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php index e246b43170..c370c00106 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/interactive_command_1.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; +use Symfony\Component\Console\Style\SymfonyStyle; //Ensure that questions have the expected outputs return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyleWithForcedLineLength($input, $output); + $output = new SymfonyStyle($input, $output); $stream = fopen('php://memory', 'r+', false); fputs($stream, "Foo\nBar\nBaz"); diff --git a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php index 00b307067d..cefd485067 100644 --- a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php @@ -13,8 +13,6 @@ namespace Symfony\Component\Console\Tests\Style; use PHPUnit_Framework_TestCase; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Tester\CommandTester; @@ -27,6 +25,7 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase protected function setUp() { + putenv('COLUMNS=121'); $this->command = new Command('sfstyle'); $this->tester = new CommandTester($this->command); } @@ -73,19 +72,3 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt')); } } - -/** - * Use this class in tests to force the line length - * and ensure a consistent output for expectations. - */ -class SymfonyStyleWithForcedLineLength extends SymfonyStyle -{ - public function __construct(InputInterface $input, OutputInterface $output) - { - parent::__construct($input, $output); - - $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength'); - $ref->setAccessible(true); - $ref->setValue($this, 120); - } -}