IniHelperTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 testWithNoIni()
  20. {
  21. $paths = array(
  22. '',
  23. );
  24. $this->setEnv($paths);
  25. $this->assertContains('does not exist', IniHelper::getMessage());
  26. $this->assertEquals($paths, IniHelper::getAll());
  27. }
  28. public function testWithLoadedIniOnly()
  29. {
  30. $paths = array(
  31. 'loaded.ini',
  32. );
  33. $this->setEnv($paths);
  34. $this->assertContains('loaded.ini', IniHelper::getMessage());
  35. $this->assertEquals($paths, IniHelper::getAll());
  36. }
  37. public function testWithLoadedIniAndAdditional()
  38. {
  39. $paths = array(
  40. 'loaded.ini',
  41. 'one.ini',
  42. 'two.ini',
  43. );
  44. $this->setEnv($paths);
  45. $this->assertContains('multiple ini files', IniHelper::getMessage());
  46. $this->assertEquals($paths, IniHelper::getAll());
  47. }
  48. public function testWithoutLoadedIniAndAdditional()
  49. {
  50. $paths = array(
  51. '',
  52. 'one.ini',
  53. 'two.ini',
  54. );
  55. $this->setEnv($paths);
  56. $this->assertContains('multiple ini files', IniHelper::getMessage());
  57. $this->assertEquals($paths, IniHelper::getAll());
  58. }
  59. public static function setUpBeforeClass()
  60. {
  61. // Save current state
  62. self::$envOriginal = getenv(IniHelper::ENV_ORIGINAL);
  63. }
  64. public static function tearDownAfterClass()
  65. {
  66. // Restore original state
  67. if (false !== self::$envOriginal) {
  68. putenv(IniHelper::ENV_ORIGINAL.'='.self::$envOriginal);
  69. } else {
  70. putenv(IniHelper::ENV_ORIGINAL);
  71. }
  72. }
  73. protected function setEnv(array $paths)
  74. {
  75. putenv(IniHelper::ENV_ORIGINAL.'='.implode(PATH_SEPARATOR, $paths));
  76. }
  77. }