Simplify argv handling
parent
fe861ac365
commit
e381abeec0
|
@ -12,7 +12,7 @@ use Composer\Console\Application;
|
||||||
|
|
||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
|
|
||||||
$xdebug = new XdebugHandler($argv);
|
$xdebug = new XdebugHandler();
|
||||||
$xdebug->check();
|
$xdebug->check();
|
||||||
unset($xdebug);
|
unset($xdebug);
|
||||||
|
|
||||||
|
|
|
@ -19,19 +19,16 @@ class XdebugHandler
|
||||||
{
|
{
|
||||||
const ENV_ALLOW = 'COMPOSER_ALLOW_XDEBUG';
|
const ENV_ALLOW = 'COMPOSER_ALLOW_XDEBUG';
|
||||||
|
|
||||||
private $argv;
|
|
||||||
private $loaded;
|
private $loaded;
|
||||||
private $tmpIni;
|
private $tmpIni;
|
||||||
private $scanDir;
|
private $scanDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $argv The global argv passed to script
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct(array $argv)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->argv = $argv;
|
|
||||||
$this->loaded = extension_loaded('xdebug');
|
$this->loaded = extension_loaded('xdebug');
|
||||||
|
|
||||||
$tmp = sys_get_temp_dir();
|
$tmp = sys_get_temp_dir();
|
||||||
$this->tmpIni = $tmp.DIRECTORY_SEPARATOR.'composer-php.ini';
|
$this->tmpIni = $tmp.DIRECTORY_SEPARATOR.'composer-php.ini';
|
||||||
$this->scanDir = $tmp.DIRECTORY_SEPARATOR.'composer-php-empty';
|
$this->scanDir = $tmp.DIRECTORY_SEPARATOR.'composer-php-empty';
|
||||||
|
@ -207,7 +204,7 @@ class XdebugHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
$phpArgs = array(PHP_BINARY, '-c', $this->tmpIni);
|
$phpArgs = array(PHP_BINARY, '-c', $this->tmpIni);
|
||||||
$params = array_merge($phpArgs, $this->getScriptArgs($this->argv));
|
$params = array_merge($phpArgs, $this->getScriptArgs($_SERVER['argv']));
|
||||||
|
|
||||||
return implode(' ', array_map(array($this, 'escape'), $params));
|
return implode(' ', array_map(array($this, 'escape'), $params));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,9 @@ class XdebugHandlerMock extends XdebugHandler
|
||||||
public $command;
|
public $command;
|
||||||
public $restarted;
|
public $restarted;
|
||||||
|
|
||||||
public function __construct(array $argv, $loaded)
|
public function __construct($loaded)
|
||||||
{
|
{
|
||||||
parent::__construct($argv);
|
parent::__construct();
|
||||||
|
|
||||||
$class = new \ReflectionClass(get_parent_class($this));
|
$class = new \ReflectionClass(get_parent_class($this));
|
||||||
$prop = $class->getProperty('loaded');
|
$prop = $class->getProperty('loaded');
|
||||||
|
|
|
@ -19,18 +19,11 @@ use Composer\Test\Mock\XdebugHandlerMock as XdebugHandler;
|
||||||
*/
|
*/
|
||||||
class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected $argv;
|
|
||||||
|
|
||||||
public function setup()
|
|
||||||
{
|
|
||||||
$this->argv = $GLOBALS['argv'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRestartWhenLoaded()
|
public function testRestartWhenLoaded()
|
||||||
{
|
{
|
||||||
$loaded = true;
|
$loaded = true;
|
||||||
|
|
||||||
$xdebug = new XdebugHandler($this->argv, $loaded);
|
$xdebug = new XdebugHandler($loaded);
|
||||||
$xdebug->check();
|
$xdebug->check();
|
||||||
$this->assertTrue($xdebug->restarted || !defined('PHP_BINARY'));
|
$this->assertTrue($xdebug->restarted || !defined('PHP_BINARY'));
|
||||||
}
|
}
|
||||||
|
@ -39,7 +32,7 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$loaded = false;
|
$loaded = false;
|
||||||
|
|
||||||
$xdebug = new XdebugHandler($this->argv, $loaded);
|
$xdebug = new XdebugHandler($loaded);
|
||||||
$xdebug->check();
|
$xdebug->check();
|
||||||
$this->assertFalse($xdebug->restarted);
|
$this->assertFalse($xdebug->restarted);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +42,7 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
||||||
$loaded = true;
|
$loaded = true;
|
||||||
putenv(XdebugHandler::ENV_ALLOW.'=1');
|
putenv(XdebugHandler::ENV_ALLOW.'=1');
|
||||||
|
|
||||||
$xdebug = new XdebugHandler($this->argv, $loaded);
|
$xdebug = new XdebugHandler($loaded);
|
||||||
$xdebug->check();
|
$xdebug->check();
|
||||||
$this->assertFalse($xdebug->restarted);
|
$this->assertFalse($xdebug->restarted);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue