diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 8f9ff366b3..1e515b8495 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -36,7 +36,7 @@ use Symfony\Component\Console\Event\ConsoleExceptionEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\Console\Exception\LogicException; -use Symfony\Component\Console\Terminal\TerminalDimensionsProvider; +use Symfony\Component\Console\Terminal; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -66,24 +66,19 @@ class Application private $definition; private $helperSet; private $dispatcher; + private $terminal; private $defaultCommand; private $singleCommand; /** - * @var TerminalDimensionsProvider + * @param string $name The name of the application + * @param string $version The version of the application */ - private $terminalDimensionsProvider; - - /** - * @param string $name The name of the application - * @param string $version The version of the application - * @param TerminalDimensionsProvider $terminalDimensionsProvider - */ - public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', TerminalDimensionsProvider $terminalDimensionsProvider = null) + public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->name = $name; $this->version = $version; - $this->terminalDimensionsProvider = $terminalDimensionsProvider ?: new TerminalDimensionsProvider(); + $this->terminal = new Terminal(); $this->defaultCommand = 'list'; $this->helperSet = $this->getDefaultHelperSet(); $this->definition = $this->getDefaultInputDefinition(); @@ -697,7 +692,7 @@ class Application */ protected function getTerminalWidth() { - return $this->terminalDimensionsProvider->getTerminalWidth(); + return $this->terminal->getWidth(); } /** @@ -707,7 +702,7 @@ class Application */ protected function getTerminalHeight() { - return $this->terminalDimensionsProvider->getTerminalWidth(); + return $this->terminal->getHeight(); } /** @@ -717,7 +712,7 @@ class Application */ public function getTerminalDimensions() { - return $this->terminalDimensionsProvider->getTerminalDimensions(); + return $this->terminal->getDimensions(); } /** @@ -732,7 +727,7 @@ class Application */ public function setTerminalDimensions($width, $height) { - $this->terminalDimensionsProvider->setTerminalDimensions($width, $height); + $this->terminal->setDimensions($width, $height); return $this; } diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index e6c9ad03e4..e0dce47a49 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -14,7 +14,7 @@ namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Exception\LogicException; -use Symfony\Component\Console\Terminal\TerminalDimensionsProvider; +use Symfony\Component\Console\Terminal; /** * The ProgressBar provides helpers to display progress output. @@ -45,21 +45,16 @@ class ProgressBar private $formatLineCount; private $messages = array(); private $overwrite = true; + private $terminal; private static $formatters; private static $formats; /** - * @var TerminalDimensionsProvider + * @param OutputInterface $output An OutputInterface instance + * @param int $max Maximum steps (0 if unknown) */ - private $terminalDimensionsProvider; - - /** - * @param OutputInterface $output An OutputInterface instance - * @param int $max Maximum steps (0 if unknown) - * @param TerminalDimensionsProvider $terminalDimensionsProvider - */ - public function __construct(OutputInterface $output, $max = 0, TerminalDimensionsProvider $terminalDimensionsProvider = null) + public function __construct(OutputInterface $output, $max = 0) { if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); @@ -67,7 +62,7 @@ class ProgressBar $this->output = $output; $this->setMaxSteps($max); - $this->terminalDimensionsProvider = $terminalDimensionsProvider ?: new TerminalDimensionsProvider(); + $this->terminal = new Terminal(); if (!$this->output->isDecorated()) { // disable overwrite when output does not support ANSI codes. @@ -443,6 +438,20 @@ class ProgressBar $this->overwrite(''); } + /** + * Gets the terminal. + * + * Can be useful to force terminal dimensions for functional tests. + * + * @return Terminal + * + * @internal + */ + public function getTerminal() + { + return $this->terminal; + } + /** * Sets the progress bar format. * @@ -617,7 +626,7 @@ class ProgressBar private function adjustLineWidthToTerminalWidth($line) { $lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line); - $terminalWidth = $this->terminalDimensionsProvider->getTerminalWidth(); + $terminalWidth = $this->terminal->getWidth(); if ($lineLength > $terminalWidth) { $newBarWidth = $this->barWidth - $lineLength + $terminalWidth; $this->setBarWidth($newBarWidth); diff --git a/src/Symfony/Component/Console/Terminal/TerminalDimensionsProvider.php b/src/Symfony/Component/Console/Terminal.php similarity index 58% rename from src/Symfony/Component/Console/Terminal/TerminalDimensionsProvider.php rename to src/Symfony/Component/Console/Terminal.php index 06d478a2ae..625a491018 100644 --- a/src/Symfony/Component/Console/Terminal/TerminalDimensionsProvider.php +++ b/src/Symfony/Component/Console/Terminal.php @@ -9,59 +9,35 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Console\Terminal; +namespace Symfony\Component\Console; -class TerminalDimensionsProvider +class Terminal { - /** - * @var int[] - */ - private $terminalDimensions = array(); - - /** - * Tries to figure out the terminal dimensions based on the current environment. - * - * @return int[] Array containing width and height - */ - public function getTerminalDimensions() - { - if ($this->terminalDimensions) { - return $this->terminalDimensions; - } - - if ($this->isWindowsEnvironment()) { - // extract [w, H] from "wxh (WxH)" - if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) { - return array((int) $matches[1], (int) $matches[2]); - } - // extract [w, h] from "wxh" - if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) { - return array((int) $matches[1], (int) $matches[2]); - } - } - - if ($sttyString = $this->getSttyColumns()) { - // extract [w, h] from "rows h; columns w;" - if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { - return array((int) $matches[2], (int) $matches[1]); - } - // extract [w, h] from "; h rows; w columns" - if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { - return array((int) $matches[2], (int) $matches[1]); - } - } - - return array(null, null); - } + private $width; + private $height; /** * Tries to figure out the terminal width in which this application runs. * * @return int|null */ - public function getTerminalWidth() + public function getWidth() { - return $this->getTerminalDimensions()[0]; + if (null === $this->width) { + $this->initDimensions(); + } + + return $this->width; + } + + /** + * Sets the terminal width. + * + * @param int + */ + public function setWidth($width) + { + $this->width = $width; } /** @@ -69,28 +45,67 @@ class TerminalDimensionsProvider * * @return int|null */ - public function getTerminalHeight() + public function getHeight() { - return $this->getTerminalDimensions()[1]; + if (null === $this->height) { + $this->initDimensions(); + } + + return $this->height; } /** - * Sets terminal dimensions. + * Sets the terminal height. * - * Can be useful to force terminal dimensions for functional tests. - * - * @param int $width - * @param int $height + * @param int */ - public function setTerminalDimensions($width, $height) + public function setHeight($height) { - $this->terminalDimensions = array($width, $height); + $this->height = $height; + } + + private function initDimensions() + { + if (null !== $this->width && null !== $this->height) { + return; + } + + $width = $height = null; + if ($this->isWindowsEnvironment()) { + if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) { + // extract [w, H] from "wxh (WxH)" + $width = (int) $matches[1]; + $height = (int) $matches[2]; + } elseif (null != $dimensions = $this->getConsoleMode()) { + // extract [w, h] from "wxh" + $width = $dimensions[0]; + $height = $dimensions[1]; + } + } elseif ($sttyString = $this->getSttyColumns()) { + if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { + // extract [w, h] from "rows h; columns w;" + $width = (int) $matches[1]; + $height = (int) $matches[2]; + } elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { + // extract [w, h] from "; h rows; w columns" + $width = (int) $matches[2]; + $heighth = (int) $matches[1]; + } + } + + if (null === $this->width) { + $this->width = $width; + } + + if (null === $this->height) { + $this->height = $height; + } } /** * Runs and parses mode CON if it's available, suppressing any error output. * - * @return string x or null if it could not be parsed + * @return array|null An array composed of the width and the height or null if it could not be parsed */ private function getConsoleMode() { @@ -110,7 +125,7 @@ class TerminalDimensionsProvider proc_close($process); if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) { - return $matches[2].'x'.$matches[1]; + return array((int) $matches[2], (int) $matches[1]); } } } diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index 4488b001b2..bf7bb54d93 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -14,7 +14,7 @@ namespace Symfony\Component\Console\Tests\Helper; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Output\StreamOutput; -use Symfony\Component\Console\Terminal\TerminalDimensionsProvider; +use Symfony\Component\Console\Terminal; /** * @group time-sensitive @@ -23,7 +23,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase { public function testMultipleStart() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->start(); $bar->advance(); $bar->start(); @@ -39,7 +39,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testAdvance() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->start(); $bar->advance(); @@ -53,7 +53,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testAdvanceWithStep() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->start(); $bar->advance(5); @@ -67,7 +67,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testAdvanceMultipleTimes() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->start(); $bar->advance(3); $bar->advance(2); @@ -83,7 +83,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testAdvanceOverMax() { - $bar = new ProgressBar($output = $this->getOutputStream(), 10, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 10); $bar->setProgress(9); $bar->advance(); $bar->advance(); @@ -106,7 +106,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase ; // max in construct, no format - $bar = new ProgressBar($output = $this->getOutputStream(), 10, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 10); $bar->start(); $bar->advance(10); $bar->finish(); @@ -115,7 +115,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, stream_get_contents($output->getStream())); // max in start, no format - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->start(10); $bar->advance(10); $bar->finish(); @@ -124,7 +124,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, stream_get_contents($output->getStream())); // max in construct, explicit format before - $bar = new ProgressBar($output = $this->getOutputStream(), 10, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 10); $bar->setFormat('normal'); $bar->start(); $bar->advance(10); @@ -134,7 +134,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, stream_get_contents($output->getStream())); // max in start, explicit format before - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->setFormat('normal'); $bar->start(10); $bar->advance(10); @@ -146,7 +146,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testCustomizations() { - $bar = new ProgressBar($output = $this->getOutputStream(), 10, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 10); $bar->setBarWidth(10); $bar->setBarCharacter('_'); $bar->setEmptyBarCharacter(' '); @@ -165,7 +165,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testDisplayWithoutStart() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->display(); rewind($output->getStream()); @@ -177,7 +177,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testDisplayWithQuietVerbosity() { - $bar = new ProgressBar($output = $this->getOutputStream(true, StreamOutput::VERBOSITY_QUIET), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(true, StreamOutput::VERBOSITY_QUIET), 50); $bar->display(); rewind($output->getStream()); @@ -189,7 +189,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testFinishWithoutStart() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->finish(); rewind($output->getStream()); @@ -201,7 +201,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testPercent() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->start(); $bar->display(); $bar->advance(); @@ -219,7 +219,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testOverwriteWithShorterLine() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%%'); $bar->start(); $bar->display(); @@ -241,7 +241,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testStartWithMax() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->setFormat('%current%/%max% [%bar%]'); $bar->start(50); $bar->advance(); @@ -256,7 +256,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testSetCurrentProgress() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->start(); $bar->display(); $bar->advance(); @@ -289,7 +289,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase */ public function testRegressProgress() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->start(); $bar->setProgress(15); $bar->setProgress(10); @@ -330,7 +330,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testMultiByteSupport() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->start(); $bar->setBarCharacter('■'); $bar->advance(3); @@ -345,7 +345,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testClear() { - $bar = new ProgressBar($output = $this->getOutputStream(), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 50); $bar->start(); $bar->setProgress(25); $bar->clear(); @@ -361,7 +361,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testPercentNotHundredBeforeComplete() { - $bar = new ProgressBar($output = $this->getOutputStream(), 200, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 200); $bar->start(); $bar->display(); $bar->advance(199); @@ -379,7 +379,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testNonDecoratedOutput() { - $bar = new ProgressBar($output = $this->getOutputStream(false), 200, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(false), 200); $bar->start(); for ($i = 0; $i < 200; ++$i) { @@ -407,7 +407,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testNonDecoratedOutputWithClear() { - $bar = new ProgressBar($output = $this->getOutputStream(false), 50, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(false), 50); $bar->start(); $bar->setProgress(25); $bar->clear(); @@ -425,7 +425,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testNonDecoratedOutputWithoutMax() { - $bar = new ProgressBar($output = $this->getOutputStream(false), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(false)); $bar->start(); $bar->advance(); @@ -440,10 +440,10 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testParallelBars() { $output = $this->getOutputStream(); - $bar1 = new ProgressBar($output, 2, $this->createTerminalDimensionsProvider()); - $bar2 = new ProgressBar($output, 3, $this->createTerminalDimensionsProvider()); + $bar1 = new ProgressBar($output, 2); + $bar2 = new ProgressBar($output, 3); $bar2->setProgressCharacter('#'); - $bar3 = new ProgressBar($output, 0, $this->createTerminalDimensionsProvider()); + $bar3 = new ProgressBar($output); $bar1->start(); $output->write("\n"); @@ -500,7 +500,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase { $output = $this->getOutputStream(); - $bar = new ProgressBar($output, 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output); $bar->start(); $bar->advance(); $bar->advance(); @@ -518,12 +518,29 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase ); } + public function testWithSmallScreen() + { + $output = $this->getOutputStream(); + + $bar = new ProgressBar($output); + $bar->getTerminal()->setDimensions(12, 50); + $bar->start(); + $bar->advance(); + + rewind($output->getStream()); + $this->assertEquals( + $this->generateOutput(' 0 [>---]'). + $this->generateOutput(' 1 [->--]'), + stream_get_contents($output->getStream()) + ); + } + public function testAddingPlaceholderFormatter() { ProgressBar::setPlaceholderFormatterDefinition('remaining_steps', function (ProgressBar $bar) { return $bar->getMaxSteps() - $bar->getProgress(); }); - $bar = new ProgressBar($output = $this->getOutputStream(), 3, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 3); $bar->setFormat(' %remaining_steps% [%bar%]'); $bar->start(); @@ -541,7 +558,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testMultilineFormat() { - $bar = new ProgressBar($output = $this->getOutputStream(), 3, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 3); $bar->setFormat("%bar%\nfoobar"); $bar->start(); @@ -561,7 +578,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testAnsiColorsAndEmojis() { - $bar = new ProgressBar($output = $this->getOutputStream(), 15, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 15); ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) { static $i = 0; $mem = 100000 * $i; @@ -604,7 +621,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase public function testSetFormat() { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->setFormat('normal'); $bar->start(); rewind($output->getStream()); @@ -613,7 +630,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase stream_get_contents($output->getStream()) ); - $bar = new ProgressBar($output = $this->getOutputStream(), 10, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream(), 10); $bar->setFormat('normal'); $bar->start(); rewind($output->getStream()); @@ -628,7 +645,7 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase */ public function testFormatsWithoutMax($format) { - $bar = new ProgressBar($output = $this->getOutputStream(), 0, $this->createTerminalDimensionsProvider()); + $bar = new ProgressBar($output = $this->getOutputStream()); $bar->setFormat($format); $bar->start(); @@ -662,15 +679,4 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase return "\x0D\x1B[2K".($count ? str_repeat("\x1B[1A\x1B[2K", $count) : '').$expected; } - - /** - * @return TerminalDimensionsProvider - */ - private function createTerminalDimensionsProvider() - { - $terminalDimensionsProvider = new TerminalDimensionsProvider(); - $terminalDimensionsProvider->setTerminalDimensions(800, 5); - - return $terminalDimensionsProvider; - } } diff --git a/src/Symfony/Component/Console/Tests/Terminal/TerminalDimensionsProviderTest.php b/src/Symfony/Component/Console/Tests/Terminal/TerminalDimensionsProviderTest.php deleted file mode 100644 index 0dbd656bfa..0000000000 --- a/src/Symfony/Component/Console/Tests/Terminal/TerminalDimensionsProviderTest.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Console\Tests\Terminal; - -use PHPUnit_Framework_TestCase; -use Symfony\Component\Console\Terminal\TerminalDimensionsProvider; -use Symfony\Component\Console\Terminal\TerminalDimensionsProviderInterface; - -class TerminalDimensionsProviderTest extends PHPUnit_Framework_TestCase -{ - /** - * @var TerminalDimensionsProviderInterface - */ - private $terminalDimensionsProvider; - - protected function setUp() - { - $this->terminalDimensionsProvider = new TerminalDimensionsProvider(); - } - - public function testGetTerminalDimensions() - { - $dimensions = $this->terminalDimensionsProvider->getTerminalDimensions(); - $this->assertCount(2, $dimensions); - - $this->terminalDimensionsProvider->setTerminalDimensions(100, 50); - $this->assertSame(array(100, 50), $this->terminalDimensionsProvider->getTerminalDimensions()); - } -} diff --git a/src/Symfony/Component/Console/Tests/TerminalTest.php b/src/Symfony/Component/Console/Tests/TerminalTest.php new file mode 100644 index 0000000000..959a82295f --- /dev/null +++ b/src/Symfony/Component/Console/Tests/TerminalTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests; + +use Symfony\Component\Console\Terminal; + +class TerminalTest extends \PHPUnit_Framework_TestCase +{ + public function testGetDimensions() + { + $terminal = new Terminal(); + $dimensions = $terminal->getDimensions(); + $this->assertCount(2, $dimensions); + + $terminal->setDimensions(100, 50); + $this->assertSame(array(100, 50), $terminal->getDimensions()); + $this->assertSame(100, $terminal->getWidth()); + $this->assertSame(50, $terminal->getHeight()); + } +}