OSTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Songshenzong\Support\Test\Core;
  3. use ReflectionClass;
  4. use ReflectionException;
  5. use Songshenzong\Support\OS;
  6. use PHPUnit\Framework\TestCase;
  7. /**
  8. * Class OSTest
  9. *
  10. * @package Songshenzong\Support\Test\Core
  11. */
  12. class OSTest extends TestCase
  13. {
  14. /**
  15. * @throws ReflectionException
  16. */
  17. public function testGetsHomeDirectoryForWindowsUser()
  18. {
  19. putenv('HOME=');
  20. putenv('HOMEDRIVE=C:');
  21. putenv('HOMEPATH=\\Users\\Support');
  22. $ref = new ReflectionClass(OS::class);
  23. $method = $ref->getMethod('getHomeDirectory');
  24. $method->setAccessible(true);
  25. $this->assertEquals('C:\\Users\\Support', $method->invoke(null));
  26. }
  27. /**
  28. * @depends testGetsHomeDirectoryForWindowsUser
  29. * @throws ReflectionException
  30. */
  31. public function testGetsHomeDirectoryForLinuxUser()
  32. {
  33. putenv('HOME=/root');
  34. putenv('HOMEDRIVE=');
  35. putenv('HOMEPATH=');
  36. $ref = new ReflectionClass(OS::class);
  37. $method = $ref->getMethod('getHomeDirectory');
  38. $method->setAccessible(true);
  39. $this->assertEquals('/root', $method->invoke(null));
  40. }
  41. }