You are here

public function WatchdogContext::checkWatchdog in Lightning Core 8.2

Same name and namespace in other branches
  1. 8.5 tests/contexts/WatchdogContext.behat.inc \WatchdogContext::checkWatchdog()
  2. 8.3 tests/contexts/WatchdogContext.behat.inc \WatchdogContext::checkWatchdog()
  3. 8.4 tests/contexts/WatchdogContext.behat.inc \WatchdogContext::checkWatchdog()

Check for errors since the scenario started.

@AfterScenario ~@errors

Parameters

\Behat\Behat\Hook\Scope\ScenarioScope $scope: The scenario scope.

File

tests/contexts/WatchdogContext.behat.inc, line 65

Class

WatchdogContext
Tracks errors logged to the database during the scenario.

Code

public function checkWatchdog(ScenarioScope $scope) {
  if ($this
    ->isDiabled($scope)) {
    return;
  }
  $db = \Drupal::database();
  if ($db
    ->schema()
    ->tableExists('watchdog')) {
    $log = $db
      ->select('watchdog', 'w')
      ->fields('w')
      ->condition('w.type', 'php', '=')
      ->condition('w.timestamp', $this->startTime, '>=')
      ->execute()
      ->fetchAll();
    if ($log) {
      foreach ($log as $error) {

        // Make the substitutions easier to read in the log.
        $error->variables = unserialize($error->variables);
        print_r($error);
      }
      throw new \Exception('PHP errors logged to watchdog in this scenario.');
    }
  }
  if ($this->uninstall) {
    \Drupal::service('module_installer')
      ->uninstall([
      'dblog',
    ]);
  }
}