Просмотр исходного кода

merged branch Seldaek/termwidth (PR #3805)

Commits
-------

7ce22f0 [Console] Add docblocks
8a2b115 [Console] Mock terminal size to prevent formatting errors on small terminals

Discussion
----------

[Console] Fixes terminal width in tests

This fixes the [tests that broke on travis-ci](http://travis-ci.org/#!/symfony/symfony/jobs/1031109) (which seems to advertise a terminal width of ~34, not sure why).
Fabien Potencier 13 лет назад
Родитель
Сommit
38e17c2e87

+ 10 - 0
src/Symfony/Component/Console/Application.php

@@ -789,6 +789,11 @@ class Application
         }
     }
 
+    /**
+     * Tries to figure out the terminal width in which this application runs
+     *
+     * @return int|null
+     */
     protected function getTerminalWidth()
     {
         if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) {
@@ -800,6 +805,11 @@ class Application
         }
     }
 
+    /**
+     * Tries to figure out the terminal height in which this application runs
+     *
+     * @return int|null
+     */
     protected function getTerminalHeight()
     {
         if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) {

+ 8 - 2
tests/Symfony/Tests/Component/Console/ApplicationTest.php

@@ -201,8 +201,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
 
     public function testSetCatchExceptions()
     {
-        $application = new Application();
+        $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
         $application->setAutoExit(false);
+        $application->expects($this->any())
+            ->method('getTerminalWidth')
+            ->will($this->returnValue(120));
         $tester = new ApplicationTester($application);
 
         $application->setCatchExceptions(true);
@@ -237,8 +240,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
 
     public function testRenderException()
     {
-        $application = new Application();
+        $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
         $application->setAutoExit(false);
+        $application->expects($this->any())
+            ->method('getTerminalWidth')
+            ->will($this->returnValue(120));
         $tester = new ApplicationTester($application);
 
         $tester->run(array('command' => 'foo'), array('decorated' => false));