AutoDiscoverTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if (\array_key_exists('CHROME_PATH', $_SERVER)) {
  21. $this->originalEnvPath = $_SERVER['CHROME_PATH'];
  22. unset($_SERVER['CHROME_PATH']);
  23. }
  24. parent::setUp();
  25. }
  26. protected function tearDown(): void
  27. {
  28. unset($_SERVER['CHROME_PATH']);
  29. if (null !== $this->originalEnvPath) {
  30. $_SERVER['CHROME_PATH'] = $this->originalEnvPath;
  31. }
  32. parent::tearDown();
  33. }
  34. public function testExplicitEnv(): void
  35. {
  36. $autoDiscover = new AutoDiscover();
  37. $_SERVER['CHROME_PATH'] = 'test-path';
  38. self::assertSame($_SERVER['CHROME_PATH'], $autoDiscover->guessChromeBinaryPath());
  39. }
  40. public function testLinux(): void
  41. {
  42. $autoDiscover = new AutoDiscover(function (): string {
  43. return 'Linux';
  44. });
  45. self::assertThat(
  46. $autoDiscover->guessChromeBinaryPath(),
  47. $this->logicalOr(
  48. 'chrome',
  49. 'google-chrome'
  50. )
  51. );
  52. }
  53. public function testMac(): void
  54. {
  55. $autoDiscover = new AutoDiscover(function (): string {
  56. return 'Darwin';
  57. });
  58. self::assertStringContainsString('.app', $autoDiscover->guessChromeBinaryPath());
  59. }
  60. public function testWindows(): void
  61. {
  62. $autoDiscover = new AutoDiscover(function (): string {
  63. return 'Windows';
  64. });
  65. self::assertStringContainsString('.exe', $autoDiscover->guessChromeBinaryPath());
  66. }
  67. }