minor #15967 [Console] Fix tests for SymfonyStyle (1ed)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Fix tests for SymfonyStyle

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15909
| License       | MIT
| Doc PR        | -

Commits
-------

7720f5c [Console] Fix tests for SymfonyStyle
This commit is contained in:
Fabien Potencier 2015-10-01 15:25:36 +02:00
commit a94d7a06d1
9 changed files with 33 additions and 17 deletions

View File

@ -2,10 +2,10 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure has single blank line at start when using block element
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->caution('Lorem ipsum dolor sit amet');
};

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure has single blank line between titles and blocks
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->title('Title');
$output->warning('Lorem ipsum dolor sit amet');
$output->title('Title');

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure has single blank line between blocks
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->warning('Warning');
$output->caution('Caution');
$output->error('Error');

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure has single blank line between two titles
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->title('First title');
$output->title('Second title');
};

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure has single blank line after any text and a title
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->write('Lorem ipsum dolor sit amet');
$output->title('First title');

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//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 SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->writeln('Lorem ipsum dolor sit amet');
$output->listing(array(

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure has proper blank line after text block when using a block like with SymfonyStyle::success
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->listing(array(
'Lorem ipsum dolor sit amet',

View File

@ -2,11 +2,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
//Ensure questions do not output anything when input is non-interactive
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyle($input, $output);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->title('Title');
$output->askHidden('Hidden question');
$output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1');

View File

@ -62,7 +62,7 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
$this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) {
$sfStyle = new SymfonyStyle($input, $output);
$sfStyle = new SymfonyStyleWithForcedLineLength($input, $output);
$sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
});
@ -71,3 +71,19 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
$this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
}
}
/**
* 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);
}
}