/** @BeforeSuite
  * @param BeforeSuiteScope $scope
  *
  * @throws \Exception
  */
 public static function loadMagentoConfiguration(BeforeSuiteScope $scope)
 {
     $environment = $scope->getEnvironment();
     if (!$environment->getSuite()->hasSetting('parameters')) {
         throw new \Exception('You must set the parameters scetion of the behat.yml');
     }
     $parameters = $environment->getSuite()->getSetting('parameters');
     if (!isset($parameters['magentoSettings'])) {
         throw new \Exception('You must include the magentoSetting in the behat.yml file');
     }
     $magentoSetting = $parameters['magentoSettings'];
     self::$_magentoSetting = $magentoSetting;
 }
 /** @BeforeSuite
  * @param BeforeSuiteScope $scope
  *
  * @throws \Exception
  */
 public static function loadErrorDetectionConfiguration(BeforeSuiteScope $scope)
 {
     $environment = $scope->getEnvironment();
     if (!$environment->getSuite()->hasSetting('parameters')) {
         $parameters['w3cValidationSettings']['errorThreshold'] = 0;
     } else {
         $parameters = $environment->getSuite()->getSetting('parameters');
     }
     if (!isset($parameters['w3cValidationSettings'])) {
         throw new \Exception('You must include the errorDetectionSettings in the behat.yml file');
     }
     $w3cValidationSettings = $parameters['w3cValidationSettings'];
     self::$_w3cValidationSettings = $w3cValidationSettings;
 }
예제 #3
0
 /**
  * Start up the built in httpd in php-5.4
  *
  * @BeforeSuite
  */
 public static function setUp(BeforeSuiteScope $scope)
 {
     $contexts = $scope->getSuite()->getSettings()['contexts'];
     $params = $contexts[0]['FeatureContext'];
     $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.');
     }
     // Empty httpd log before starting new server
     if (is_writeable($params['httpdLog'])) {
         file_put_contents($params['httpdLog'], '');
     }
     $pid = self::startBuiltInHttpd($url['host'], $port, $params['documentRoot'], $params['router'], $params['httpdLog']);
     if (!$pid) {
         // Could not start the httpd for some reason
         throw new RuntimeException('Could not start the web server');
     }
     // Try to connect
     $start = microtime(true);
     $connected = false;
     while (microtime(true) - $start <= (int) $params['timeout']) {
         if (self::canConnectToHttpd($url['host'], $port)) {
             $connected = true;
             break;
         }
     }
     if (!$connected) {
         throw new RuntimeException(sprintf('Could not connect to the web server within the given timeframe (%d second(s))', $params['timeout']));
     }
     // Register a shutdown function that will automatically shut down the httpd
     register_shutdown_function(function () use($pid) {
         exec('kill ' . $pid);
     });
     self::$testSessionId = uniqid('', true);
 }
예제 #4
0
 /**
  * @BeforeSuite
  */
 public static function setup(BeforeSuiteScope $scope)
 {
     self::$suite = $scope->getSuite();
 }
예제 #5
0
 /** 
  * 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}");
         }
     }
 }