diff --git a/src/Drush/Commands/PlaywrightDrushCommands.php b/src/Drush/Commands/PlaywrightDrushCommands.php index 5436516..d2087ac 100644 --- a/src/Drush/Commands/PlaywrightDrushCommands.php +++ b/src/Drush/Commands/PlaywrightDrushCommands.php @@ -286,19 +286,25 @@ public function getCorsParams() { } /** - * Check if there are errors in watchdog and exits when found. + * Check if there are errors in watchdog. * * @param int $timestamp * Timestamp from when to look for errors. * @param bool $fail_on_notice * Variable to change severity level of which watchdog errors to load. + * @param bool $verbose + * Print error messages as well. * * @bootstrap full * @command test:checkWatchdog * @aliases testcw */ - public function checkForWatchdogErrors(int $timestamp, bool $fail_on_notice = FALSE) : int { + public function checkForWatchdogErrors(int $timestamp, bool $fail_on_notice = FALSE, bool $verbose = FALSE) : string { $severity_level = $fail_on_notice ? RfcLogLevel::NOTICE : RfcLogLevel::WARNING; + // Check if microtime was used as parameter and convert to unix timestamp. + if ($timestamp > 10 ** 13) { + $timestamp /= 1000; + } $query = $this->getDatabaseConnection()->select('watchdog', 'w'); $query->fields("w"); $query->condition('timestamp', $timestamp, '>'); @@ -306,17 +312,27 @@ public function checkForWatchdogErrors(int $timestamp, bool $fail_on_notice = FA $query->condition('type', 'php'); $query->orderBy('timestamp', 'DESC'); $log_entries = $query->execute()->fetchAllAssoc('wid'); + $result = [ + 'numberOfErrors' => 0, + 'errors' => [], + ]; if ($log_entries && is_array($log_entries)) { foreach ($log_entries as $entry) { // @see \Drupal\dblog\Controller\DbLogController::formatMessage() - $variables = (array) @unserialize($entry->variables, ['allowed_classes' => FALSE]); - $message = (new FormattableMarkup($entry->message, $variables)); - $this->writeln($message . ':' . $entry->wid . ':' . $entry->type . ':' . $entry->severity); - $this->stderr(); - exit; + $variables = @unserialize($entry->variables); + if ($verbose) { + $message = (new FormattableMarkup($entry->message, $variables)); + $result['errors'][] = [ + 'message' => $message ?? '', + 'wid' => $entry->wid ?? '', + 'type' => $entry->type ?? '', + 'severity' => $entry->severity ?? '', + ]; + } + $result['numberOfErrors'] += 1; } } - return 0; + return json_encode($result, JSON_PRETTY_PRINT); } } diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index c4fe14e..4f6524a 100644 --- a/tests/helpers/drupal-commands.js +++ b/tests/helpers/drupal-commands.js @@ -90,11 +90,12 @@ module.exports = { * * @param timestamp Timestamp from when to look for errors. * @param fail_on_notice Boolean to change severity level of watchdog errors. - * @returns {Promise} The result. + * @returns {Promise} The json result. */ checkWatchdogErrors: async (timestamp, fail_on_notice) => { - const result = drush(`test:checkWatchdog "${timestamp}" "${fail_on_notice}"`); - return result.toString(); + const result = drush(`test:checkWatchdog "${timestamp}" "${fail_on_notice}" "1"`); + const json = JSON.parse(result.toString()); + return parseInt(json['numberOfErrors']); }, /**