IniHelperTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /**
  14. * @author John Stevenson <john-stevenson@blueyonder.co.uk>
  15. */
  16. class IniHelperTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public static $envOriginal;
  19. public function testWithLoadedIni()
  20. {
  21. $paths = array(
  22. 'loaded.ini',
  23. );
  24. $this->setEnv($paths);
  25. $this->assertContains('loaded.ini', IniHelper::getMessage());
  26. $this->assertEquals($paths, IniHelper::getAll());
  27. }
  28. public function testWithoutLoadedIni()
  29. {
  30. $paths = array(
  31. '',
  32. 'one.ini',
  33. 'two.ini',
  34. );
  35. $this->setEnv($paths);
  36. $this->assertContains('does not exist', IniHelper::getMessage());
  37. $this->assertEquals($paths, IniHelper::getAll());
  38. }
  39. public static function setUpBeforeClass()
  40. {
  41. // Save current state
  42. self::$envOriginal = getenv(IniHelper::ENV_ORIGINAL);
  43. }
  44. public static function tearDownAfterClass()
  45. {
  46. // Restore original state
  47. if (false !== self::$envOriginal) {
  48. putenv(IniHelper::ENV_ORIGINAL.'='.self::$envOriginal);
  49. } else {
  50. putenv(IniHelper::ENV_ORIGINAL);
  51. }
  52. }
  53. protected function setEnv(array $paths)
  54. {
  55. putenv(IniHelper::ENV_ORIGINAL.'='.implode(PATH_SEPARATOR, $paths));
  56. }
  57. }