IniHelperTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Util;
  12. use Composer\Util\IniHelper;
  13. use Composer\XdebugHandler\XdebugHandler;
  14. use Composer\Test\TestCase;
  15. /**
  16. * @author John Stevenson <john-stevenson@blueyonder.co.uk>
  17. */
  18. class IniHelperTest extends TestCase
  19. {
  20. public static $envOriginal;
  21. public function testWithNoIni()
  22. {
  23. $paths = array(
  24. '',
  25. );
  26. $this->setEnv($paths);
  27. $this->assertContains('does not exist', IniHelper::getMessage());
  28. $this->assertEquals($paths, IniHelper::getAll());
  29. }
  30. public function testWithLoadedIniOnly()
  31. {
  32. $paths = array(
  33. 'loaded.ini',
  34. );
  35. $this->setEnv($paths);
  36. $this->assertContains('loaded.ini', IniHelper::getMessage());
  37. }
  38. public function testWithLoadedIniAndAdditional()
  39. {
  40. $paths = array(
  41. 'loaded.ini',
  42. 'one.ini',
  43. 'two.ini',
  44. );
  45. $this->setEnv($paths);
  46. $this->assertContains('multiple ini files', IniHelper::getMessage());
  47. $this->assertEquals($paths, IniHelper::getAll());
  48. }
  49. public function testWithoutLoadedIniAndAdditional()
  50. {
  51. $paths = array(
  52. '',
  53. 'one.ini',
  54. 'two.ini',
  55. );
  56. $this->setEnv($paths);
  57. $this->assertContains('multiple ini files', IniHelper::getMessage());
  58. $this->assertEquals($paths, IniHelper::getAll());
  59. }
  60. public static function setUpBeforeClass()
  61. {
  62. // Register our name with XdebugHandler
  63. $xdebug = new XdebugHandler('composer');
  64. // Save current state
  65. self::$envOriginal = getenv('COMPOSER_ORIGINAL_INIS');
  66. }
  67. public static function tearDownAfterClass()
  68. {
  69. // Restore original state
  70. if (false !== self::$envOriginal) {
  71. putenv('COMPOSER_ORIGINAL_INIS='.self::$envOriginal);
  72. } else {
  73. putenv('COMPOSER_ORIGINAL_INIS');
  74. }
  75. }
  76. protected function setEnv(array $paths)
  77. {
  78. putenv('COMPOSER_ORIGINAL_INIS='.implode(PATH_SEPARATOR, $paths));
  79. }
  80. }