Fix and rationalize tests

main
johnstevenson 8 years ago
parent 589b1d6fa2
commit 0256f62b3b

@ -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;
}
}

@ -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');
}
}

Loading…
Cancel
Save