From e381abeec05bdcd7fb7695616aa42ddb2155e091 Mon Sep 17 00:00:00 2001 From: johnstevenson Date: Sat, 3 Sep 2016 19:00:41 +0100 Subject: [PATCH] Simplify argv handling --- bin/composer | 2 +- src/Composer/XdebugHandler.php | 9 +++------ tests/Composer/Test/Mock/XdebugHandlerMock.php | 4 ++-- tests/Composer/Test/XdebugHandlerTest.php | 13 +++---------- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/bin/composer b/bin/composer index 927ebd1cb..c2b428e06 100755 --- a/bin/composer +++ b/bin/composer @@ -12,7 +12,7 @@ use Composer\Console\Application; error_reporting(-1); -$xdebug = new XdebugHandler($argv); +$xdebug = new XdebugHandler(); $xdebug->check(); unset($xdebug); diff --git a/src/Composer/XdebugHandler.php b/src/Composer/XdebugHandler.php index 1b445d2b2..59c0f2574 100644 --- a/src/Composer/XdebugHandler.php +++ b/src/Composer/XdebugHandler.php @@ -19,19 +19,16 @@ class XdebugHandler { const ENV_ALLOW = 'COMPOSER_ALLOW_XDEBUG'; - private $argv; private $loaded; private $tmpIni; 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'); - $tmp = sys_get_temp_dir(); $this->tmpIni = $tmp.DIRECTORY_SEPARATOR.'composer-php.ini'; $this->scanDir = $tmp.DIRECTORY_SEPARATOR.'composer-php-empty'; @@ -207,7 +204,7 @@ class XdebugHandler } $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)); } diff --git a/tests/Composer/Test/Mock/XdebugHandlerMock.php b/tests/Composer/Test/Mock/XdebugHandlerMock.php index bf462b318..612dd7bf9 100644 --- a/tests/Composer/Test/Mock/XdebugHandlerMock.php +++ b/tests/Composer/Test/Mock/XdebugHandlerMock.php @@ -18,9 +18,9 @@ class XdebugHandlerMock extends XdebugHandler public $command; public $restarted; - public function __construct(array $argv, $loaded) + public function __construct($loaded) { - parent::__construct($argv); + parent::__construct(); $class = new \ReflectionClass(get_parent_class($this)); $prop = $class->getProperty('loaded'); diff --git a/tests/Composer/Test/XdebugHandlerTest.php b/tests/Composer/Test/XdebugHandlerTest.php index 3917896cd..860c173de 100644 --- a/tests/Composer/Test/XdebugHandlerTest.php +++ b/tests/Composer/Test/XdebugHandlerTest.php @@ -19,18 +19,11 @@ use Composer\Test\Mock\XdebugHandlerMock as XdebugHandler; */ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase { - protected $argv; - - public function setup() - { - $this->argv = $GLOBALS['argv']; - } - public function testRestartWhenLoaded() { $loaded = true; - $xdebug = new XdebugHandler($this->argv, $loaded); + $xdebug = new XdebugHandler($loaded); $xdebug->check(); $this->assertTrue($xdebug->restarted || !defined('PHP_BINARY')); } @@ -39,7 +32,7 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase { $loaded = false; - $xdebug = new XdebugHandler($this->argv, $loaded); + $xdebug = new XdebugHandler($loaded); $xdebug->check(); $this->assertFalse($xdebug->restarted); } @@ -49,7 +42,7 @@ class XdebugHandlerTest extends \PHPUnit_Framework_TestCase $loaded = true; putenv(XdebugHandler::ENV_ALLOW.'=1'); - $xdebug = new XdebugHandler($this->argv, $loaded); + $xdebug = new XdebugHandler($loaded); $xdebug->check(); $this->assertFalse($xdebug->restarted); }