1
0
Fork 0
composer/tests/Composer/Test/Util/IniHelperTest.php

104 lines
2.5 KiB
PHP
Raw Normal View History

<?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;
2020-02-07 03:18:45 +00:00
use Composer\Test\TestCase;
/**
* @author John Stevenson <john-stevenson@blueyonder.co.uk>
*/
class IniHelperTest extends TestCase
{
2021-10-16 08:16:06 +00:00
/**
* @var string|false
*/
public static $envOriginal;
public function testWithNoIni(): void
{
$paths = array(
'',
);
$this->setEnv($paths);
$this->assertStringContainsString('does not exist', IniHelper::getMessage());
$this->assertEquals($paths, IniHelper::getAll());
}
public function testWithLoadedIniOnly(): void
{
$paths = array(
'loaded.ini',
);
$this->setEnv($paths);
$this->assertStringContainsString('loaded.ini', IniHelper::getMessage());
}
public function testWithLoadedIniAndAdditional(): void
{
$paths = array(
'loaded.ini',
'one.ini',
'two.ini',
);
$this->setEnv($paths);
$this->assertStringContainsString('multiple ini files', IniHelper::getMessage());
$this->assertEquals($paths, IniHelper::getAll());
}
public function testWithoutLoadedIniAndAdditional(): void
{
$paths = array(
'',
'one.ini',
'two.ini',
);
$this->setEnv($paths);
$this->assertStringContainsString('multiple ini files', IniHelper::getMessage());
$this->assertEquals($paths, IniHelper::getAll());
}
2021-12-08 16:03:05 +00:00
public static function setUpBeforeClass(): void
{
2017-11-23 15:52:48 +00:00
// Register our name with XdebugHandler
$xdebug = new XdebugHandler('composer');
// Save current state
2017-11-23 15:52:48 +00:00
self::$envOriginal = getenv('COMPOSER_ORIGINAL_INIS');
}
2021-12-08 16:03:05 +00:00
public static function tearDownAfterClass(): void
{
// Restore original state
if (false !== self::$envOriginal) {
2017-11-23 15:52:48 +00:00
putenv('COMPOSER_ORIGINAL_INIS='.self::$envOriginal);
} else {
2017-11-23 15:52:48 +00:00
putenv('COMPOSER_ORIGINAL_INIS');
}
}
2021-10-27 14:18:46 +00:00
/**
* @param string[] $paths
*
* @return void
*/
protected function setEnv(array $paths): void
{
2017-11-23 15:52:48 +00:00
putenv('COMPOSER_ORIGINAL_INIS='.implode(PATH_SEPARATOR, $paths));
}
}