PlatformTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Platform;
  13. /**
  14. * PlatformTest
  15. *
  16. * @author Niels Keurentjes <niels.keurentjes@omines.com>
  17. */
  18. class PlatformTest extends \PHPUnit_Framework_TestCase
  19. {
  20. public function testExpandPath()
  21. {
  22. putenv('TESTENV=/home/test');
  23. if (Platform::isWindows()) {
  24. $this->assertEquals('/home/test/myPath', Platform::expandPath('%TESTENV%/myPath'));
  25. } else {
  26. $this->assertEquals('/home/test/myPath', Platform::expandPath('$TESTENV/myPath'));
  27. }
  28. $this->assertEquals((getenv('HOME') ?: getenv('USERPROFILE')) . '/test', Platform::expandPath('~/test'));
  29. }
  30. public function testIsWindows()
  31. {
  32. // Compare 2 common tests for Windows to the built-in Windows test
  33. $this->assertEquals(('\\' === DIRECTORY_SEPARATOR), Platform::isWindows());
  34. $this->assertEquals(defined('PHP_WINDOWS_VERSION_MAJOR'), Platform::isWindows());
  35. }
  36. }