Permalink
Browse files

[Console] Added a way to set terminal dimensions

  • Loading branch information...
1 parent a315258 commit 872a494b88fba2f62be85e0bc8441e7946bb6ba6 @lyrixx lyrixx committed with fabpot Jul 29, 2013
Showing with 38 additions and 0 deletions.
  1. +22 −0 Application.php
  2. +1 −0 CHANGELOG.md
  3. +15 −0 Tests/ApplicationTest.php
View
@@ -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)) {
@@ -854,6 +859,23 @@ public function getTerminalDimensions()
return array(null, null);
}
+ /**
+ * 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.
*
View
@@ -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
@@ -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;

0 comments on commit 872a494

Please sign in to comment.