HttpEnabledTestCase.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Symfony\Component\Process\Process;
  12. class HttpEnabledTestCase extends BaseTestCase
  13. {
  14. /** @var Process */
  15. private static $process;
  16. public static function setUpBeforeClass(): void
  17. {
  18. parent::setUpBeforeClass();
  19. self::$process = new Process([
  20. 'php',
  21. '-S',
  22. 'localhost:8083',
  23. '-t',
  24. __DIR__.'/resources/static-web',
  25. ]);
  26. self::$process->start();
  27. \usleep(80000); //wait for server to get going
  28. // ensure it started
  29. if (!self::$process->isRunning()) {
  30. $message = self::$process->getErrorOutput();
  31. throw new \Exception('Cannot start webserver for tests: '.$message);
  32. }
  33. }
  34. public static function tearDownAfterClass(): void
  35. {
  36. parent::tearDownAfterClass();
  37. self::$process->stop();
  38. }
  39. public function getHttpHost()
  40. {
  41. return 'localhost:8083';
  42. }
  43. protected static function sitePath(string $file): string
  44. {
  45. return 'http://localhost:8083/'.$file;
  46. }
  47. }