1
0
Fork 0

Simplify argv handling

pull/5580/head
johnstevenson 2016-09-03 19:00:41 +01:00
parent fe861ac365
commit e381abeec0
4 changed files with 9 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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