10000 minor #15967 [Console] Fix tests for SymfonyStyle (1ed) · symfony/symfony@a94d7a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a94d7a0

Browse files
committed
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
2 parents 0a615f9 + 7720f5c commit a94d7a0

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has single blank line at start when using block element
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010
$output->caution('Lorem ipsum dolor sit amet');
1111
};

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has single blank line between titles and blocks
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010
$output->title('Title');
1111
$output->warning('Lorem ipsum dolor sit amet');
1212
$output->title('Title');

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has single blank line between blocks
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010
$output->warning('Warning');
1111
$output->caution('Caution');
1212
$output->error('Error');

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has single blank line between two titles
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010
$output->title('First title');
1111
$output->title('Second title');
1212
};

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has single blank line after any text and a title
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010

1111
$output->write('Lorem ipsum dolor sit amet');
1212
$output->title('First title');

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has proper line ending before outputing a text block like with SymfonyStyle::listing() or SymfonyStyle::text()
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010

1111
$output->writeln('Lorem ipsum dolor sit amet');
1212
$output->listing(array(

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure has proper blank line after text block when using a block like with SymfonyStyle::success
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010

1111
$output->listing(array(
1212
'Lorem ipsum dolor sit amet',

src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\OutputInterface;
5-
use Symfony\Component\Console\Style\SymfonyStyle;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
66

77
//Ensure questions do not output anything when input is non-interactive
88
return function (InputInterface $input, OutputInterface $output) {
9-
$output = new SymfonyStyle($input, $output);
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
1010
$output->title('Title');
1111
$output->askHidden('Hidden question');
1212
$output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1');

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testLongWordsBlockWrapping()
6262
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
6363

6464
$this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) {
65-
$sfStyle = new SymfonyStyle($input, $output);
65+
$sfStyle = new SymfonyStyleWithForcedLineLength($input, $output);
6666
$sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
6767
});
6868

@@ -71,3 +71,19 @@ public function testLongWordsBlockWrapping()
7171
$this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
7272
}
7373
}
74+
75+
/**
76+
* Use this class in tests to force the line length
77+
* and ensure a consistent output for expectations.
78+
*/
79+
class SymfonyStyleWithForcedLineLength extends SymfonyStyle
80+
{
81+
public function __construct(InputInterface $input, OutputInterface $output)
82+
{
83+
parent::__construct($input, $output);
84+
85+
$ref = new \ReflectionProperty(get_parent_class($this), 'lineLength');
86+
$ref->setAccessible(true);
87+
$ref->setValue($this, 120);
88+
}
89+
}

0 commit comments

Comments
 (0)
0