From 0256f62b3b8985c7df162d4105741378beb303c3 Mon Sep 17 00:00:00 2001 From: johnstevenson Date: Tue, 6 Sep 2016 20:17:18 +0100 Subject: [PATCH] Fix and rationalize tests --- .../Composer/Test/Mock/XdebugHandlerMock.php | 5 +-- tests/Composer/Test/XdebugHandlerTest.php | 31 +++++++++---------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/tests/Composer/Test/Mock/XdebugHandlerMock.php b/tests/Composer/Test/Mock/XdebugHandlerMock.php index 7f07a58b4..65fe07329 100644 --- a/tests/Composer/Test/Mock/XdebugHandlerMock.php +++ b/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; } } diff --git a/tests/Composer/Test/XdebugHandlerTest.php b/tests/Composer/Test/XdebugHandlerTest.php index d9875e9a1..57222fa5a 100644 --- a/tests/Composer/Test/XdebugHandlerTest.php +++ b/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'); } }