[Console] Fix tests for SymfonyStyle
This commit is contained in:
parent
f80e6c63d7
commit
7720f5c70b
@ -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\Style\SymfonyStyle;
|
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
|
||||||
|
|
||||||
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\Style\SymfonyStyle;
|
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
|
||||||
|
|
||||||
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\Style\SymfonyStyle;
|
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
|
||||||
|
|
||||||
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\Style\SymfonyStyle;
|
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
|
||||||
|
|
||||||
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\Style\SymfonyStyle;
|
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
|
||||||
|
|
||||||
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\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()
|
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\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
|
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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\Style\SymfonyStyle;
|
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
|
||||||
|
|
||||||
//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 SymfonyStyle($input, $output);
|
$output = new SymfonyStyleWithForcedLineLength($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');
|
||||||
|
@ -62,7 +62,7 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
|
|||||||
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
|
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
|
||||||
|
|
||||||
$this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) {
|
$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);
|
$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), ' § '));
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user