diff --git a/README.md b/README.md index 39b7614..f0523f1 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ Enable and configure the extension in your `codeception.yaml` # Limit the size of error messages in extended mode. 0 = unlimited. Default value: 80 extendedMaxLength: 80 + # Limit the amount of reported errors in extended mode. 0 = unlimited. Default value: 0 + extendedMaxErrors: 10 + # customize your message with additional prefix and/or suffix messagePrefix: '*Smoke-Test*' @@ -66,4 +69,4 @@ Example Dependencies ----- -This package uses the package [maknz/slack](https://github.com/maknz/slack) to communicate with the Slack API. \ No newline at end of file +This package uses the package [maknz/slack](https://github.com/maknz/slack) to communicate with the Slack API. diff --git a/src/Extension/SlackExtension.php b/src/Extension/SlackExtension.php index 86af6b6..31a6cc1 100644 --- a/src/Extension/SlackExtension.php +++ b/src/Extension/SlackExtension.php @@ -103,6 +103,11 @@ class SlackExtension extends Extension */ protected $extendedMaxLength = 80; + /** + * @var int|null The maximum amount of errors to send + */ + protected $extendedMaxErrors = 0; + /** * Setup Slack client and message object. * @@ -185,6 +190,10 @@ public function _initialize() $this->extended = true; } + if (isset($this->config['extendedMaxErrors'])) { + $this->extendedMaxErrors = max((int) $this->config['extendedMaxErrors'], 0); + } + if (isset($this->config['extendedMaxLength'])) { $this->extendedMaxLength = intval($this->config['extendedMaxLength']); } @@ -286,8 +295,14 @@ private function sendFailMessage(TestResult $result) */ private function attachExtendedInformation(Message &$message, TestResult $result) { $fields = []; + $failures = array_merge($result->failures(), $result->errors()); + $omittedFailures = 0; + if ($this->extendedMaxErrors > 0) { + $omittedFailures = count($failures) - $this->extendedMaxErrors; + $failures = array_slice($failures, 0, $this->extendedMaxErrors); + } - foreach (array_merge($result->failures(), $result->errors()) as $failure) { + foreach ($failures as $failure) { /** * @var $failure TestFailure */ @@ -309,6 +324,13 @@ private function attachExtendedInformation(Message &$message, TestResult $result ]; } + if ($omittedFailures > 0) { + $fields[] = [ + 'title' => sprintf('%d other tests...', $omittedFailures), + 'value' => '', + ]; + } + $message->attach([ 'color' => 'danger', 'fields' => $fields