minor #19111 [Console] simplified tests (fabpot)
This PR was merged into the 3.2-dev branch.
Discussion
----------
[Console] simplified tests
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | no
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Commits
-------
85e5060
[Console] simplified tests
This commit is contained in:
commit
92d80c93b3
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure has single blank line at start when using block element
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->caution('Lorem ipsum dolor sit amet');
|
$output->caution('Lorem ipsum dolor sit amet');
|
||||||
};
|
};
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure has single blank line between titles and blocks
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->title('Title');
|
$output->title('Title');
|
||||||
$output->warning('Lorem ipsum dolor sit amet');
|
$output->warning('Lorem ipsum dolor sit amet');
|
||||||
$output->title('Title');
|
$output->title('Title');
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//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) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->block(
|
$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',
|
'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',
|
'CUSTOM',
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
// ensure long words are properly wrapped in blocks
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
|
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
|
||||||
$sfStyle = new SymfonyStyleWithForcedLineLength($input, $output);
|
$sfStyle = new SymfonyStyle($input, $output);
|
||||||
$sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
|
$sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
|
||||||
};
|
};
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
// 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) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->comment(
|
$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'
|
'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'
|
||||||
);
|
);
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure has single blank line between blocks
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->warning('Warning');
|
$output->warning('Warning');
|
||||||
$output->caution('Caution');
|
$output->caution('Caution');
|
||||||
$output->error('Error');
|
$output->error('Error');
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure has single blank line between two titles
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->title('First title');
|
$output->title('First title');
|
||||||
$output->title('Second title');
|
$output->title('Second title');
|
||||||
};
|
};
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure has single blank line after any text and a title
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$output->write('Lorem ipsum dolor sit amet');
|
$output->write('Lorem ipsum dolor sit amet');
|
||||||
$output->title('First title');
|
$output->title('First title');
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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()
|
//Ensure has proper line ending before outputing a text block like with SymfonyStyle::listing() or SymfonyStyle::text()
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$output->writeln('Lorem ipsum dolor sit amet');
|
$output->writeln('Lorem ipsum dolor sit amet');
|
||||||
$output->listing(array(
|
$output->listing(array(
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure has proper blank line after text block when using a block like with SymfonyStyle::success
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$output->listing(array(
|
$output->listing(array(
|
||||||
'Lorem ipsum dolor sit amet',
|
'Lorem ipsum dolor sit amet',
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure questions do not output anything when input is non-interactive
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->title('Title');
|
$output->title('Title');
|
||||||
$output->askHidden('Hidden question');
|
$output->askHidden('Hidden question');
|
||||||
$output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1');
|
$output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1');
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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;
|
use Symfony\Component\Console\Helper\TableCell;
|
||||||
|
|
||||||
//Ensure formatting tables when using multiple headers with 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'),
|
array('978-0804169127', 'Divine Comedy'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$output->table($headers, $rows);
|
$output->table($headers, $rows);
|
||||||
};
|
};
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure that all lines are aligned to the begin of the first line in a multi-line block
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
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);
|
$output->block(array('Custom block', 'Second custom block line'), 'CUSTOM', 'fg=white;bg=green', 'X ', true);
|
||||||
};
|
};
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
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
|
//Ensure that questions have the expected outputs
|
||||||
return function (InputInterface $input, OutputInterface $output) {
|
return function (InputInterface $input, OutputInterface $output) {
|
||||||
$output = new SymfonyStyleWithForcedLineLength($input, $output);
|
$output = new SymfonyStyle($input, $output);
|
||||||
$stream = fopen('php://memory', 'r+', false);
|
$stream = fopen('php://memory', 'r+', false);
|
||||||
|
|
||||||
fputs($stream, "Foo\nBar\nBaz");
|
fputs($stream, "Foo\nBar\nBaz");
|
||||||
|
@ -13,8 +13,6 @@ namespace Symfony\Component\Console\Tests\Style;
|
|||||||
|
|
||||||
use PHPUnit_Framework_TestCase;
|
use PHPUnit_Framework_TestCase;
|
||||||
use Symfony\Component\Console\Command\Command;
|
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\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
|
||||||
@ -27,6 +25,7 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
|
putenv('COLUMNS=121');
|
||||||
$this->command = new Command('sfstyle');
|
$this->command = new Command('sfstyle');
|
||||||
$this->tester = new CommandTester($this->command);
|
$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'));
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user