/**
  * Allow Behat to be killed after the first failed scenario
  * To enable, in your command prompt run:
  *  export BEHAT_DIE_ON_FAILURE=true;
  * @AfterScenario
  * @param AfterScenarioScope $scope
  */
 public function dieOnFailedScenario(AfterScenarioScope $scope)
 {
     if (99 === $scope->getTestResult()->getResultCode()) {
         if (isset($_SERVER['BEHAT_DIE_ON_FAILURE'])) {
             die("BEHAT_DIE_ON_FAILURE is defined. Killing Full Process\n");
         }
     }
 }
Example #2
0
 /** @AfterScenario */
 public function printLastResponseWhenScenarioFail(AfterScenarioScope $scope)
 {
     if ($scope->getTestResult()->getResultCode() === TestResult::FAILED) {
         echo "Last response:\n";
         echo "Code " . $this->getSession()->getStatusCode() . "\n";
         $this->printLastResponse();
     }
 }
 /**
  * @AfterScenario
  *
  * Reset the values after the last scenario of the feature and disable the testing app
  * @param AfterScenarioScope $event
  */
 public function undoChangingParameters(AfterScenarioScope $event)
 {
     $scenarios = $event->getFeature()->getScenarios();
     if ($event->getScenario() === end($scenarios)) {
         $user = $this->currentUser;
         $this->currentUser = '******';
         $this->resetAppConfigs();
         $this->setStatusTestingApp(false);
         $this->currentUser = $user;
     }
 }
 /**
  * @AfterScenario
  */
 public function takeDatabaseDumpAfterFailedStep(AfterScenarioScope $scope)
 {
     if ($this->screenshot_dir && TestResult::FAILED === $scope->getTestResult()->getResultCode()) {
         $feature = $scope->getFeature();
         $scenario = $scope->getScenario();
         $filename = basename($feature->getFile(), '.feature') . '-' . $scenario->getLine();
         $filepath = $this->screenshot_dir . $filename . '.sql';
         try {
             $dump = new Mysqldump('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD);
             $dump->start($filepath);
         } catch (\Exception $e) {
             echo 'mysqldump-php error: ' . $e->getMessage();
         }
     }
 }
Example #5
0
 /**
  * @AfterScenario
  *
  * Delete any tempusers that were created outside of 'Given users'.
  */
 public function deleteTempUsers(AfterScenarioScope $scope)
 {
     if ($scope->getScenario()->hasTag('deleteTempUsers')) {
         // Get all users that start with tempUser*
         $results = db_query("SELECT uid from users where name like 'tempuser%%'");
         foreach ($results as $user) {
             user_delete($user->uid);
         }
     }
 }
 protected function dieOnFailedScenario(AfterScenarioScope $scope)
 {
     if (99 === $scope->getTestResult()->getResultCode()) {
         if (isset($_SERVER['BEHAT_DIE_ON_FAILURE'])) {
             die("\n\nBEHAT_DIE_ON_FAILURE is defined\n\nKilling Full Process\n\n\n\n");
         } else {
             echo "\n\nTo die on failure, please run:\nexport BEHAT_DIE_ON_FAILURE=true;\n\n";
         }
     }
 }
 /**
  * @param  AfterScenarioScope $scope
  */
 public function printTesterOutputOnFailure($scope)
 {
     if (!$scope->getTestResult()->isPassed()) {
         $outputFile = sys_get_temp_dir() . '/behat-test-runner.out';
         $this->filesystem->dumpFile($outputFile, $this->behatProcess->getOutput() . $this->behatProcess->getErrorOutput());
         throw new RuntimeException("Output of secondary Behat process has been saved to {$outputFile}");
     }
 }