Exemplo n.º 1
0
 /**
  * Initializes Mink instance and sessions.
  *
  * @param   Behat\Behat\Event\SuiteEvent $event
  *
  * @BeforeSuite
  */
 public static function initMinkSessions(SuiteEvent $event)
 {
     self::$parameters = static::mergeConfigWithDefaults(static::getDefaultParameters(), $event->getContextParameters());
     if (null === self::$mink) {
         self::$mink = new Mink();
     }
     static::registerMinkSessions(self::$mink, self::$parameters);
 }
Exemplo n.º 2
0
 /**
  * Listens to "suite.after" event.
  *
  * @param   Behat\Behat\Event\SuiteEvent    $event
  *
  * @uses    printFailedSteps()
  * @uses    printPendingSteps()
  * @uses    printSummary()
  * @uses    printUndefinedStepsSnippets()
  */
 public function afterSuite(SuiteEvent $event)
 {
     $logger = $event->getLogger();
     $this->writeln("\n");
     $this->printFailedSteps($logger);
     $this->printPendingSteps($logger);
     $this->printSummary($logger);
     $this->printUndefinedStepsSnippets($logger);
 }
Exemplo n.º 3
0
 /**
  * @BeforeSuite
  */
 public static function downloadDrupal(SuiteEvent $event)
 {
     self::setup($event->getContextParameters());
     self::clearDrupal();
     $path = dirname(self::$drupalPath);
     $folder = basename(self::$drupalPath);
     self::drushCommand(sprintf('dl drupal --drupal-project-rename="%s" --destination="%s"', $folder, $path));
     $finder = Finder::create()->exclude('tests')->in(self::$modulePath);
     self::$filesystem->mirror(self::$modulePath, self::$drupalPath . '/sites/all/modules/raven', $finder, array('override' => TRUE, 'delete' => TRUE));
 }
Exemplo n.º 4
0
 /**
  * @BeforeSuite
  */
 public static function prepareDB(SuiteEvent $event)
 {
     $parameters = $event->getContextParameters();
     if (empty($parameters['config_file']) || !is_readable($parameters['config_file'])) {
         throw new Exception(sprintf('Config file %s does not exist or not readable', $parameters['config_file']));
     }
     if (empty($parameters['sql_init_file']) || !is_readable($parameters['sql_init_file'])) {
         throw new Exception(sprintf('sql init file %s does not exist or not readable', $parameters['sql_init_file']));
     }
     self::getConnection($parameters);
     self::executeSqlFile($parameters['sql_init_file']);
 }
 /**
  * @BeforeSuite
  */
 public static function blackMagicBeforeSuite(SuiteEvent $event)
 {
     $parameters = $event->getContextParameters();
     if (false === isset($parameters['customDate'])) {
         throw new \Exception("You don't have customDate in your behat parameters\n");
     }
     global $custom_date;
     self::$_date = $custom_date = $parameters['customDate'];
     $rename = function ($real_name, $fake_name) {
         runkit_function_rename($real_name, "real_{$real_name}");
         runkit_function_rename("ETNA\\FeatureContext\\{$fake_name}", $real_name);
     };
     $rename("time", "fakeTime");
     $rename("date", "fakeDate");
     $rename("strtotime", "fakeStrtotime");
 }
 /**
  * @AfterSuite
  */
 public static function codeCoverageStop(SuiteEvent $event)
 {
     $parameters = $event->getContextParameters();
     switch (true) {
         case false === isset($parameters['enableCodeCoverage']):
         case true !== $parameters['enableCodeCoverage']:
             return;
     }
     self::$_coverage->stop();
     $writer = new PHP_CodeCoverage_Report_PHP();
     $writer->process(self::$_coverage, getcwd() . "/{$parameters['coveragePath']}.php");
     $writer = new PHP_CodeCoverage_Report_HTML();
     $writer->process(self::$_coverage, getcwd() . "/{$parameters['coveragePath']}");
     $writer = new PHP_CodeCoverage_Report_Clover();
     $writer->process(self::$_coverage, getcwd() . "/{$parameters['coveragePath']}.clover.xml");
     exec("open " . getcwd() . '/' . self::$_parameters['coveragePath'] . "/index.html");
 }
 /**
  * Kill the httpd process if it has been started when the tests have finished
  *
  * @AfterSuite
  */
 public static function tearDown(SuiteEvent $event)
 {
     $parameters = $event->getContextParameters();
     if ($parameters['enableCodeCoverage']) {
         $client = new Client($parameters['url']);
         $response = $client->get('/', array('X-Enable-Coverage' => 1, 'X-Test-Session-Id' => self::$testSessionId, 'X-Collect-Coverage' => 1))->send();
         $data = unserialize((string) $response->getBody());
         $filter = new PHP_CodeCoverage_Filter();
         foreach ($parameters['whitelist'] as $dir) {
             $filter->addDirectoryToWhitelist($dir);
         }
         $coverage = new PHP_CodeCoverage(null, $filter);
         $coverage->append($data, 'behat-suite');
         $report = new PHP_CodeCoverage_Report_HTML();
         $report->process($coverage, $parameters['coveragePath']);
     }
     if (self::$pid) {
         self::killProcess(self::$pid);
     }
 }
Exemplo n.º 8
0
 /**
  * Listens to "suite.after" event.
  *
  * @param SuiteEvent $event
  *
  * @uses printUndefinedStepsSnippets()
  */
 public function afterSuite(SuiteEvent $event)
 {
     $logger = $event->getLogger();
     $this->writeln();
     $this->printSnippets($logger);
 }
Exemplo n.º 9
0
 /**
  * Listens to "suite.after" event.
  *
  * @param SuiteEvent $event
  *
  * @uses printSuiteFooter()
  */
 public function afterSuite(SuiteEvent $event)
 {
     $this->printSuiteFooter($event->getLogger());
 }
Exemplo n.º 10
0
 /**
  * @param SuiteEvent $event
  * @return int
  * @throws RuntimeException
  */
 private static function setUpPhantomServer(SuiteEvent $event)
 {
     // Fetch config
     $params = $event->getContextParameters();
     $port = $params['phantom_port'];
     if (self::canConnectToHttpd('localhost', $port)) {
         throw new RuntimeException('Something is already running on port ' . $port . '. Aborting tests.');
     }
     // Try to start the phantom server
     $pid = self::startPhantom($port);
     if (!$pid) {
         throw new RuntimeException('Could not start the phantom 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('localhost', $port)) {
             $connected = true;
             break;
         }
     }
     if (!$connected) {
         self::killProcess($pid);
         throw new RuntimeException(sprintf('Could not connect to the phantom server within the given timeframe (%d second(s))', $params['timeout']));
     }
     return $pid;
 }
Exemplo n.º 11
0
 /**
  * @BeforeSuite
  */
 public static function initUrls(\Behat\Behat\Event\SuiteEvent $event)
 {
     $params = $event->getContextParameters();
     if (isset($params['client_url'])) {
         $url = $params['client_url'];
         self::$clientUrl = strpos($url, 'http://') === 0 ? $params['client_url'] : $params['base_url'] . $params['client_url'];
     }
     if (isset($params['admin_url'])) {
         $url = $params['admin_url'];
         self::$adminUrl = strpos($url, 'http://') === 0 ? $url : $params['base_url'] . $url;
     }
 }
Exemplo n.º 12
0
 /**
  * Initializes Mink instance and sessions.
  *
  * @param   Behat\Behat\Event\SuiteEvent $event
  *
  * @BeforeSuite
  */
 public static function initMinkSessions(SuiteEvent $event)
 {
     if (null === self::$mink) {
         $kernel = $event->getContextParameters();
         self::$mink = $kernel->getContainer()->get('behat.mink');
     }
 }
Exemplo n.º 13
0
 /**
  * @BeforeSuite
  */
 public static function prepareDB(SuiteEvent $event)
 {
     $parameters = $event->getContextParameters();
     if (empty($parameters['config_file']) || !is_readable($parameters['config_file'])) {
         throw new \Exception(sprintf('Config file %s does not exist or not readable', $parameters['config_file']));
     }
     if (!empty($parameters['sql_init_file']) && is_readable($parameters['sql_init_file'])) {
         self::getConfigDb($parameters)->readSqlFile($parameters['sql_init_file']);
     }
 }