TestHttpServer.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Contracts\HttpClient\Test;
  11. use Symfony\Component\Process\PhpExecutableFinder;
  12. use Symfony\Component\Process\Process;
  13. /**
  14. * @experimental in 1.1
  15. */
  16. class TestHttpServer
  17. {
  18. private static $server;
  19. public static function start()
  20. {
  21. if (null !== self::$server) {
  22. return;
  23. }
  24. $finder = new PhpExecutableFinder();
  25. $process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
  26. $process->setWorkingDirectory(__DIR__.'/Fixtures/web');
  27. $process->setTimeout(300);
  28. $process->start();
  29. self::$server = new class() {
  30. public $process;
  31. public function __destruct()
  32. {
  33. $this->process->stop();
  34. }
  35. };
  36. self::$server->process = $process;
  37. sleep('\\' === \DIRECTORY_SEPARATOR ? 10 : 1);
  38. }
  39. }