8000 [Console] Fix tests for SymfonyStyle by 1ed · Pull Request #15967 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix tests for SymfonyStyle #15967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 17 additions & 1 deletion src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testLongWordsBlockWrapping()
$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);
});

Expand All @@ -71,3 +71,19 @@ public function testLongWordsBlockWrapping()
$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);
}
}
0