2016-08-05 10:43:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test;
|
|
|
|
|
2016-09-06 13:48:37 +00:00
|
|
|
use Composer\Test\Mock\XdebugHandlerMock;
|
2016-11-19 20:50:15 +00:00
|
|
|
use Composer\Util\IniHelper;
|
2016-08-05 10:43:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author John Stevenson <john-stevenson@blueyonder.co.uk>
|
2016-09-21 16:22:24 +00:00
|
|
|
*
|
|
|
|
* We use PHP_BINARY which only became available in PHP 5.4 *
|
|
|
|
* @requires PHP 5.4
|
2016-08-05 10:43:56 +00:00
|
|
|
*/
|
|
|
|
class XdebugHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-11-19 20:50:15 +00:00
|
|
|
public static $env = array();
|
2016-09-06 19:17:18 +00:00
|
|
|
|
2016-08-05 10:43:56 +00:00
|
|
|
public function testRestartWhenLoaded()
|
|
|
|
{
|
|
|
|
$loaded = true;
|
|
|
|
|
2016-09-06 13:48:37 +00:00
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
2016-08-05 10:43:56 +00:00
|
|
|
$xdebug->check();
|
2016-09-21 16:22:24 +00:00
|
|
|
$this->assertTrue($xdebug->restarted);
|
2016-11-21 11:52:56 +00:00
|
|
|
$this->assertInternalType('string', getenv(IniHelper::ENV_ORIGINAL));
|
2016-08-05 10:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoRestartWhenNotLoaded()
|
|
|
|
{
|
|
|
|
$loaded = false;
|
|
|
|
|
2016-09-06 13:48:37 +00:00
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
2016-08-05 10:43:56 +00:00
|
|
|
$xdebug->check();
|
|
|
|
$this->assertFalse($xdebug->restarted);
|
2016-11-21 11:52:56 +00:00
|
|
|
$this->assertFalse(getenv(IniHelper::ENV_ORIGINAL));
|
2016-08-05 10:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoRestartWhenLoadedAndAllowed()
|
|
|
|
{
|
|
|
|
$loaded = true;
|
2016-09-06 13:48:37 +00:00
|
|
|
putenv(XdebugHandlerMock::ENV_ALLOW.'=1');
|
2016-08-05 10:43:56 +00:00
|
|
|
|
2016-09-06 13:48:37 +00:00
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
2016-08-05 10:43:56 +00:00
|
|
|
$xdebug->check();
|
|
|
|
$this->assertFalse($xdebug->restarted);
|
|
|
|
}
|
2016-09-06 13:48:37 +00:00
|
|
|
|
2016-09-21 16:22:24 +00:00
|
|
|
public function testEnvAllow()
|
|
|
|
{
|
|
|
|
$loaded = true;
|
|
|
|
|
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
|
|
|
$xdebug->check();
|
|
|
|
$expected = XdebugHandlerMock::RESTART_ID;
|
|
|
|
$this->assertEquals($expected, getenv(XdebugHandlerMock::ENV_ALLOW));
|
|
|
|
|
|
|
|
// Mimic restart
|
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
|
|
|
$xdebug->check();
|
|
|
|
$this->assertFalse($xdebug->restarted);
|
|
|
|
$this->assertFalse(getenv(XdebugHandlerMock::ENV_ALLOW));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnvAllowWithScanDir()
|
|
|
|
{
|
|
|
|
$loaded = true;
|
|
|
|
$dir = '/some/where';
|
|
|
|
putenv('PHP_INI_SCAN_DIR='.$dir);
|
|
|
|
|
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
|
|
|
$xdebug->check();
|
|
|
|
$expected = XdebugHandlerMock::RESTART_ID.'|'.$dir;
|
|
|
|
$this->assertEquals($expected, getenv(XdebugHandlerMock::ENV_ALLOW));
|
|
|
|
|
|
|
|
// Mimic setting scan dir and restart
|
|
|
|
putenv('PHP_INI_SCAN_DIR=');
|
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
|
|
|
$xdebug->check();
|
|
|
|
$this->assertEquals($dir, getenv('PHP_INI_SCAN_DIR'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnvAllowWithEmptyScanDir()
|
|
|
|
{
|
|
|
|
$loaded = true;
|
|
|
|
putenv('PHP_INI_SCAN_DIR=');
|
|
|
|
|
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
|
|
|
$xdebug->check();
|
|
|
|
$expected = XdebugHandlerMock::RESTART_ID.'|';
|
|
|
|
$this->assertEquals($expected, getenv(XdebugHandlerMock::ENV_ALLOW));
|
|
|
|
|
|
|
|
// Unset scan dir and mimic restart
|
|
|
|
putenv('PHP_INI_SCAN_DIR');
|
|
|
|
$xdebug = new XdebugHandlerMock($loaded);
|
|
|
|
$xdebug->check();
|
|
|
|
$this->assertEquals('', getenv('PHP_INI_SCAN_DIR'));
|
|
|
|
}
|
|
|
|
|
2016-09-06 19:17:18 +00:00
|
|
|
public static function setUpBeforeClass()
|
2016-09-06 13:48:37 +00:00
|
|
|
{
|
2016-11-19 20:50:15 +00:00
|
|
|
// Save current state
|
|
|
|
$names = array(
|
|
|
|
XdebugHandlerMock::ENV_ALLOW,
|
|
|
|
'PHP_INI_SCAN_DIR',
|
|
|
|
IniHelper::ENV_ORIGINAL,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($names as $name) {
|
|
|
|
self::$env[$name] = getenv($name);
|
|
|
|
}
|
2016-09-06 13:48:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 19:17:18 +00:00
|
|
|
public static function tearDownAfterClass()
|
2016-09-06 13:48:37 +00:00
|
|
|
{
|
2016-11-19 20:50:15 +00:00
|
|
|
// Restore original state
|
|
|
|
foreach (self::$env as $name => $value) {
|
|
|
|
if (false !== $value) {
|
|
|
|
putenv($name.'='.$value);
|
|
|
|
} else {
|
|
|
|
putenv($name);
|
|
|
|
}
|
2016-09-06 19:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-06 13:48:37 +00:00
|
|
|
|
2016-09-06 19:17:18 +00:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2016-11-19 20:50:15 +00:00
|
|
|
// Ensure env is unset
|
2016-09-21 16:22:24 +00:00
|
|
|
putenv(XdebugHandlerMock::ENV_ALLOW);
|
|
|
|
putenv('PHP_INI_SCAN_DIR');
|
2016-11-19 20:50:15 +00:00
|
|
|
putenv(IniHelper::ENV_ORIGINAL);
|
2016-09-06 13:48:37 +00:00
|
|
|
}
|
2016-08-05 10:43:56 +00:00
|
|
|
}
|