1
0
Fork 0

Fix and rationalize tests

pull/5580/head
johnstevenson 2016-09-06 20:17:18 +01:00
parent 589b1d6fa2
commit 0256f62b3b
2 changed files with 20 additions and 26 deletions

View File

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

View File

@ -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
public static function setUpBeforeClass()
{
self::$envAllow = (bool) getenv(XdebugHandlerMock::ENV_ALLOW);
}
public static function tearDownAfterClass()
{
if (self::$envAllow) {
putenv(XdebugHandlerMock::ENV_ALLOW.'=1');
} else {
putenv(XdebugHandlerMock::ENV_ALLOW.'=0');
}
}
public function testForceColorSupport()
protected function setUp()
{
$xdebug = new XdebugHandlerMock();
$xdebug->output->setDecorated(true);
$xdebug->check();
$args = explode(' ', $xdebug->command);
$this->assertTrue(in_array('--ansi', $args) || !defined('PHP_BINARY'));
}
public function testIgnoreColorSupportIfNoAnsi()
{
$xdebug = new XdebugHandlerMock();
$xdebug->output->setDecorated(true);
$_SERVER['argv'][] = '--no-ansi';
$xdebug->check();
$args = explode(' ', $xdebug->command);
$this->assertTrue(!in_array('--ansi', $args) || !defined('PHP_BINARY'));
putenv(XdebugHandlerMock::ENV_ALLOW.'=0');
}
}