Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Console] Added a way to set terminal dimensions

  • Loading branch information...
commit 872a494b88fba2f62be85e0bc8441e7946bb6ba6 1 parent a315258
@lyrixx lyrixx authored fabpot committed
Showing with 38 additions and 0 deletions.
  1. +22 −0 Application.php
  2. +1 −0  CHANGELOG.md
  3. +15 −0 Tests/ApplicationTest.php
View
22 Application.php
@@ -66,6 +66,7 @@ class Application
private $definition;
private $helperSet;
private $dispatcher;
+ private $terminalDimensions;
/**
* Constructor.
@@ -829,6 +830,10 @@ protected function getTerminalHeight()
*/
public function getTerminalDimensions()
{
+ if ($this->terminalDimensions) {
+ return $this->terminalDimensions;
+ }
+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
// extract [w, H] from "wxh (WxH)"
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
@@ -855,6 +860,23 @@ public function getTerminalDimensions()
}
/**
+ * Sets terminal dimensions.
+ *
+ * Can be useful to force terminal dimensions for functional tests.
+ *
+ * @param integer $width The width
+ * @param integer $height The height
+ *
+ * @return Application The current application
+ */
+ public function setTerminalDimensions($width, $height)
+ {
+ $this->terminalDimensions = array($width, $height);
+
+ return $this;
+ }
+
+ /**
* Configures the input and output instances based on the user arguments and options.
*
* @param InputInterface $input An InputInterface instance
View
1  CHANGELOG.md
@@ -4,6 +4,7 @@ CHANGELOG
2.4.0
-----
+ * added a way to force terminal dimensions
* [BC BREAK] made descriptors use output instead of returning a string
2.3.0
View
15 Tests/ApplicationTest.php
@@ -792,6 +792,21 @@ public function testRunDispatchesAllEventsWithException()
$this->assertContains('before.foo.after.caught.', $tester->getDisplay());
}
+ public function testTerminalDimensions()
+ {
+ $application = new Application();
+ $originalDimensions = $application->getTerminalDimensions();
+ $this->assertCount(2, $originalDimensions);
+
+ $width = 80;
+ if ($originalDimensions[0] == $width) {
+ $width = 100;
+ }
+
+ $application->setTerminalDimensions($width, 80);
+ $this->assertSame(array($width, 80), $application->getTerminalDimensions());
+ }
+
protected function getDispatcher()
{
$dispatcher = new EventDispatcher;
Please sign in to comment.
Something went wrong with that request. Please try again.