Pārlūkot izejas kodu

Fix and rationalize tests

johnstevenson 8 gadi atpakaļ
vecāks
revīzija
0256f62b3b

+ 1 - 4
tests/Composer/Test/Mock/XdebugHandlerMock.php

@@ -16,7 +16,6 @@ use Composer\XdebugHandler;
 
 class XdebugHandlerMock extends XdebugHandler
 {
-    public $command;
     public $restarted;
     public $output;
 
@@ -25,19 +24,17 @@ class XdebugHandlerMock extends XdebugHandler
         $this->output = Factory::createOutput();
         parent::__construct($this->output);
 
-        $loaded = $loaded === null ? true: $loaded;
+        $loaded = null === $loaded ? true: $loaded;
         $class = new \ReflectionClass(get_parent_class($this));
         $prop = $class->getProperty('loaded');
         $prop->setAccessible(true);
         $prop->setValue($this, $loaded);
 
-        $this->command = '';
         $this->restarted = false;
     }
 
     protected function restart($command)
     {
-        $this->command = $command;
         $this->restarted = true;
     }
 }

+ 14 - 17
tests/Composer/Test/XdebugHandlerTest.php

@@ -19,6 +19,8 @@ use Composer\Test\Mock\XdebugHandlerMock;
  */
 class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
 {
+    public static $envAllow;
+
     public function testRestartWhenLoaded()
     {
         $loaded = true;
@@ -45,29 +47,24 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
         $xdebug = new XdebugHandlerMock($loaded);
         $xdebug->check();
         $this->assertFalse($xdebug->restarted);
-
-        // Clear env for subsequent tests
-        putenv(XdebugHandlerMock::ENV_ALLOW.'=0');
     }
 
-    public function testForceColorSupport()
+    public static function setUpBeforeClass()
     {
-        $xdebug = new XdebugHandlerMock();
-        $xdebug->output->setDecorated(true);
-        $xdebug->check();
-
-        $args = explode(' ', $xdebug->command);
-        $this->assertTrue(in_array('--ansi', $args) || !defined('PHP_BINARY'));
+        self::$envAllow = (bool) getenv(XdebugHandlerMock::ENV_ALLOW);
     }
 
-    public function testIgnoreColorSupportIfNoAnsi()
+    public static function tearDownAfterClass()
     {
-        $xdebug = new XdebugHandlerMock();
-        $xdebug->output->setDecorated(true);
-        $_SERVER['argv'][] = '--no-ansi';
-        $xdebug->check();
+        if (self::$envAllow) {
+            putenv(XdebugHandlerMock::ENV_ALLOW.'=1');
+        } else {
+            putenv(XdebugHandlerMock::ENV_ALLOW.'=0');
+        }
+    }
 
-        $args = explode(' ', $xdebug->command);
-        $this->assertTrue(!in_array('--ansi', $args) || !defined('PHP_BINARY'));
+    protected function setUp()
+    {
+        putenv(XdebugHandlerMock::ENV_ALLOW.'=0');
     }
 }