2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2016-11-19 20:50:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\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
|
|
|
{
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var string|false
|
|
|
|
*/
|
2016-11-19 20:50:15 +00:00
|
|
|
public static $envOriginal;
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWithNoIni(): void
|
2017-11-02 12:46:09 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$paths = [
|
2017-11-02 12:46:09 +00:00
|
|
|
'',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2017-11-02 12:46:09 +00:00
|
|
|
|
|
|
|
$this->setEnv($paths);
|
2020-09-10 15:21:11 +00:00
|
|
|
$this->assertStringContainsString('does not exist', IniHelper::getMessage());
|
2017-11-02 12:46:09 +00:00
|
|
|
$this->assertEquals($paths, IniHelper::getAll());
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWithLoadedIniOnly(): void
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$paths = [
|
2016-11-19 20:50:15 +00:00
|
|
|
'loaded.ini',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2016-11-19 20:50:15 +00:00
|
|
|
|
|
|
|
$this->setEnv($paths);
|
2020-09-10 15:21:11 +00:00
|
|
|
$this->assertStringContainsString('loaded.ini', IniHelper::getMessage());
|
2016-11-19 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWithLoadedIniAndAdditional(): void
|
2017-11-02 12:46:09 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$paths = [
|
2017-11-02 12:46:09 +00:00
|
|
|
'loaded.ini',
|
|
|
|
'one.ini',
|
|
|
|
'two.ini',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2017-11-02 12:46:09 +00:00
|
|
|
|
|
|
|
$this->setEnv($paths);
|
2020-09-10 15:21:11 +00:00
|
|
|
$this->assertStringContainsString('multiple ini files', IniHelper::getMessage());
|
2017-11-02 12:46:09 +00:00
|
|
|
$this->assertEquals($paths, IniHelper::getAll());
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWithoutLoadedIniAndAdditional(): void
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$paths = [
|
2016-11-19 20:50:15 +00:00
|
|
|
'',
|
|
|
|
'one.ini',
|
|
|
|
'two.ini',
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2016-11-19 20:50:15 +00:00
|
|
|
|
|
|
|
$this->setEnv($paths);
|
2020-09-10 15:21:11 +00:00
|
|
|
$this->assertStringContainsString('multiple ini files', IniHelper::getMessage());
|
2016-11-19 20:50:15 +00:00
|
|
|
$this->assertEquals($paths, IniHelper::getAll());
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public static function setUpBeforeClass(): void
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public static function tearDownAfterClass(): void
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 14:18:46 +00:00
|
|
|
/**
|
|
|
|
* @param string[] $paths
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
protected function setEnv(array $paths): void
|
2016-11-19 20:50:15 +00:00
|
|
|
{
|
2017-11-23 15:52:48 +00:00
|
|
|
putenv('COMPOSER_ORIGINAL_INIS='.implode(PATH_SEPARATOR, $paths));
|
2016-11-19 20:50:15 +00:00
|
|
|
}
|
|
|
|
}
|