summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Tests/Style/SymfonyStyleTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/console/Tests/Style/SymfonyStyleTest.php')
-rw-r--r--vendor/symfony/console/Tests/Style/SymfonyStyleTest.php81
1 files changed, 54 insertions, 27 deletions
diff --git a/vendor/symfony/console/Tests/Style/SymfonyStyleTest.php b/vendor/symfony/console/Tests/Style/SymfonyStyleTest.php
index 889a9c82..865bb33f 100644
--- a/vendor/symfony/console/Tests/Style/SymfonyStyleTest.php
+++ b/vendor/symfony/console/Tests/Style/SymfonyStyleTest.php
@@ -11,14 +11,16 @@
namespace Symfony\Component\Console\Tests\Style;
-use PHPUnit_Framework_TestCase;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Tester\CommandTester;
+use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Output\ConsoleOutputInterface;
+use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
-use Symfony\Component\Console\Tester\CommandTester;
-class SymfonyStyleTest extends PHPUnit_Framework_TestCase
+class SymfonyStyleTest extends TestCase
{
/** @var Command */
protected $command;
@@ -27,12 +29,14 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
protected function setUp()
{
+ putenv('COLUMNS=121');
$this->command = new Command('sfstyle');
$this->tester = new CommandTester($this->command);
}
protected function tearDown()
{
+ putenv('COLUMNS');
$this->command = null;
$this->tester = null;
}
@@ -48,6 +52,24 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
$this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
}
+ /**
+ * @dataProvider inputInteractiveCommandToOutputFilesProvider
+ */
+ public function testInteractiveOutputs($inputCommandFilepath, $outputFilepath)
+ {
+ $code = require $inputCommandFilepath;
+ $this->command->setCode($code);
+ $this->tester->execute(array(), array('interactive' => true, 'decorated' => false));
+ $this->assertStringEqualsFile($outputFilepath, $this->tester->getDisplay(true));
+ }
+
+ public function inputInteractiveCommandToOutputFilesProvider()
+ {
+ $baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
+
+ return array_map(null, glob($baseDir.'/command/interactive_command_*.php'), glob($baseDir.'/output/interactive_output_*.txt'));
+ }
+
public function inputCommandToOutputFilesProvider()
{
$baseDir = __DIR__.'/../Fixtures/Style/SymfonyStyle';
@@ -55,35 +77,40 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase
return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
}
- public function testLongWordsBlockWrapping()
+ public function testGetErrorStyle()
{
- $word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygovgollhjvhvljfezefeqifzeiqgiqzhrsdgihqzridghqridghqirshdghdghieridgheirhsdgehrsdvhqrsidhqshdgihrsidvqhneriqsdvjzergetsrfhgrstsfhsetsfhesrhdgtesfhbzrtfbrztvetbsdfbrsdfbrn';
- $wordLength = strlen($word);
- $maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
+ $input = $this->getMockBuilder(InputInterface::class)->getMock();
- $this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) {
- $sfStyle = new SymfonyStyleWithForcedLineLength($input, $output);
- $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false);
- });
+ $errorOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $errorOutput
+ ->method('getFormatter')
+ ->willReturn(new OutputFormatter());
+ $errorOutput
+ ->expects($this->once())
+ ->method('write');
- $this->tester->execute(array(), array('interactive' => false, 'decorated' => false));
- $expectedCount = (int) ceil($wordLength / ($maxLineLength)) + (int) ($wordLength > $maxLineLength - 5);
- $this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § '));
+ $output = $this->getMockBuilder(ConsoleOutputInterface::class)->getMock();
+ $output
+ ->method('getFormatter')
+ ->willReturn(new OutputFormatter());
+ $output
+ ->expects($this->once())
+ ->method('getErrorOutput')
+ ->willReturn($errorOutput);
+
+ $io = new SymfonyStyle($input, $output);
+ $io->getErrorStyle()->write('');
}
-}
-/**
- * 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)
+ public function testGetErrorStyleUsesTheCurrentOutputIfNoErrorOutputIsAvailable()
{
- parent::__construct($input, $output);
+ $output = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $output
+ ->method('getFormatter')
+ ->willReturn(new OutputFormatter());
+
+ $style = new SymfonyStyle($this->getMockBuilder(InputInterface::class)->getMock(), $output);
- $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength');
- $ref->setAccessible(true);
- $ref->setValue($this, 120);
+ $this->assertInstanceOf(SymfonyStyle::class, $style->getErrorStyle());
}
}