/**
  * Start up the web server
  *
  * @BeforeSuite
  */
 public static function setUp(SuiteEvent $event)
 {
     // Fetch config
     $params = $event->getContextParameters();
     $url = parse_url($params['url']);
     $port = !empty($url['port']) ? $url['port'] : 80;
     if (self::canConnectToHttpd($url['host'], $port)) {
         throw new RuntimeException('Something is already running on ' . $params['url'] . '. Aborting tests.');
     }
     // Try to start the web server
     self::$pid = self::startBuiltInHttpd($url['host'], $port, $params['documentRoot'], $params['router']);
     if (!self::$pid) {
         throw new RuntimeException('Could not start the web server');
     }
     $start = microtime(true);
     $connected = false;
     // Try to connect until the time spent exceeds the timeout specified in the configuration
     while (microtime(true) - $start <= (int) $params['timeout']) {
         if (self::canConnectToHttpd($url['host'], $port)) {
             $connected = true;
             break;
         }
     }
     if (!$connected) {
         self::killProcess(self::$pid);
         throw new RuntimeException(sprintf('Could not connect to the web server within the given timeframe (%d second(s))', $params['timeout']));
     }
     self::$testSessionId = uniqid('behat-coverage-', true);
 }
Пример #2
0
 /**
  * @BeforeSuite
  */
 public static function startServer()
 {
     self::$pid = (int) `php --server=localhost:8000 --docroot="public" >> var/php-cli-server.log 2>&1 & echo \$!`;
     sleep(1);
 }