/**
  * Initializes context.
  */
 public function __construct()
 {
     parent::__construct();
     $this->testDir = __DIR__ . '/../';
 }
 /**
  * @BeforeSuite
  */
 public static function bootstrapApp()
 {
     self::$app = (require __DIR__ . '/../../app/app.php');
 }
 /** 
  * Starts the phantomjs GhostDriver for UI tests
  * 
  * Add a 'ghostd:   { port: 8643 }' suite setting to your `behat.yml` file.
  * 
  * @BeforeSuite
  */
 public static function startGhostDriver(BeforeSuiteScope $scope)
 {
     if ($scope->getSuite()->hasSetting('ghostd')) {
         $config = $scope->getSuite()->getSetting('ghostd');
         $port = $config['port'];
         $host = 'localhost';
         // launch if not already up
         if (!self::serverIsUp($host, $port)) {
             $command = "phantomjs --webdriver={$port} >/dev/null 2>&1 & echo \$!";
             $output = trim(shell_exec($command));
             self::$ghostDriverPid = is_numeric($output) ? intval($output) : null;
         }
         // check that the server is running, wait up to 5 seconds
         $attempts = 0;
         do {
             $up = self::serverIsUp($host, $port);
             $attempts++;
             usleep(100000);
             // 0.1 sec
         } while (!$up && $attempts < 50);
         if (!$up) {
             self::stopProcess(self::$ghostDriverPid);
             // just in case it *did* start but did not respond in time
             throw new \RuntimeException("Could not start ghost driver at {$host}:{$port}");
         }
     }
 }