2016-11-19 20:50:15 +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\Util;
|
|
|
|
|
|
|
|
use Composer\Util\IniHelper;
|
2017-11-23 15:52:48 +00:00
|
|
|
use Composer\XdebugHandler\XdebugHandler;
|
2017-11-04 14:52:13 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-11-19 20:50:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author John Stevenson <john-stevenson@blueyonder.co.uk>
|
|
|
|
*/
|
2017-11-04 14:52:13 +00:00
|
|
|
class IniHelperTest extends TestCase
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
|
|
|
public static $envOriginal;
|
|
|
|
|
2017-11-02 12:46:09 +00:00
|
|
|
public function testWithNoIni()
|
|
|
|
{
|
|
|
|
$paths = array(
|
|
|
|
'',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setEnv($paths);
|
|
|
|
$this->assertContains('does not exist', IniHelper::getMessage());
|
|
|
|
$this->assertEquals($paths, IniHelper::getAll());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithLoadedIniOnly()
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
|
|
|
$paths = array(
|
|
|
|
'loaded.ini',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setEnv($paths);
|
|
|
|
$this->assertContains('loaded.ini', IniHelper::getMessage());
|
|
|
|
}
|
|
|
|
|
2017-11-02 12:46:09 +00:00
|
|
|
public function testWithLoadedIniAndAdditional()
|
|
|
|
{
|
|
|
|
$paths = array(
|
|
|
|
'loaded.ini',
|
|
|
|
'one.ini',
|
|
|
|
'two.ini',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setEnv($paths);
|
|
|
|
$this->assertContains('multiple ini files', IniHelper::getMessage());
|
|
|
|
$this->assertEquals($paths, IniHelper::getAll());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWithoutLoadedIniAndAdditional()
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
|
|
|
$paths = array(
|
|
|
|
'',
|
|
|
|
'one.ini',
|
|
|
|
'two.ini',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setEnv($paths);
|
2017-11-02 12:46:09 +00:00
|
|
|
$this->assertContains('multiple ini files', IniHelper::getMessage());
|
2016-11-19 20:50:15 +00:00
|
|
|
$this->assertEquals($paths, IniHelper::getAll());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
2017-11-23 15:52:48 +00:00
|
|
|
// Register our name with XdebugHandler
|
|
|
|
$xdebug = new XdebugHandler('composer');
|
2016-11-19 20:50:15 +00:00
|
|
|
// Save current state
|
2017-11-23 15:52:48 +00:00
|
|
|
self::$envOriginal = getenv('COMPOSER_ORIGINAL_INIS');
|
2016-11-19 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function tearDownAfterClass()
|
|
|
|
{
|
|
|
|
// Restore original state
|
|
|
|
if (false !== self::$envOriginal) {
|
2017-11-23 15:52:48 +00:00
|
|
|
putenv('COMPOSER_ORIGINAL_INIS='.self::$envOriginal);
|
2016-11-19 20:50:15 +00:00
|
|
|
} else {
|
2017-11-23 15:52:48 +00:00
|
|
|
putenv('COMPOSER_ORIGINAL_INIS');
|
2016-11-19 20:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setEnv(array $paths)
|
|
|
|
{
|
2017-11-23 15:52:48 +00:00
|
|
|
putenv('COMPOSER_ORIGINAL_INIS='.implode(PATH_SEPARATOR, $paths));
|
2016-11-19 20:50:15 +00:00
|
|
|
}
|
|
|
|
}
|