AutoDiscoverTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of Chrome PHP.
  4. *
  5. * (c) Soufiane Ghzal <sghzal@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace HeadlessChromium\Test;
  11. use HeadlessChromium\AutoDiscover;
  12. /**
  13. * @covers \HeadlessChromium\AutoDiscover
  14. */
  15. class AutoDiscoverTest extends BaseTestCase
  16. {
  17. private $originalEnvPath = null;
  18. protected function setUp(): void
  19. {
  20. $this->originalEnvPath = null ?? $_SERVER['CHROME_PATH'];
  21. unset($_SERVER['CHROME_PATH']);
  22. parent::setUp();
  23. }
  24. protected function tearDown(): void
  25. {
  26. unset($_SERVER['CHROME_PATH']);
  27. if (null !== $this->originalEnvPath) {
  28. $_SERVER['CHROME_PATH'] = $this->originalEnvPath;
  29. }
  30. parent::tearDown();
  31. }
  32. public function testExplicitEnv(): void
  33. {
  34. $autoDiscover = new AutoDiscover();
  35. $_SERVER['CHROME_PATH'] = 'test-path';
  36. $this->assertSame($_SERVER['CHROME_PATH'], $autoDiscover->guessChromeBinaryPath());
  37. }
  38. public function testLinux(): void
  39. {
  40. $autoDiscover = new AutoDiscover(function (): string {
  41. return 'Linux';
  42. });
  43. $this->assertSame('chrome', $autoDiscover->guessChromeBinaryPath());
  44. }
  45. public function testMac(): void
  46. {
  47. $autoDiscover = new AutoDiscover(function (): string {
  48. return 'Darwin';
  49. });
  50. $this->assertStringContainsString('.app', $autoDiscover->guessChromeBinaryPath());
  51. }
  52. public function testWindows(): void
  53. {
  54. $autoDiscover = new AutoDiscover(function (): string {
  55. return 'Windows';
  56. });
  57. $this->assertStringContainsString('.exe', $autoDiscover->guessChromeBinaryPath());
  58. }
  59. }