From 4dd48394f0d5494c118240f935a43ce2a6393591 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Fri, 8 Oct 2021 15:19:15 +0200 Subject: [PATCH] Adding clickable `editorUrl` from `codeception.yml` Closes https://github.com/Codeception/Codeception/issues/6259 I followed the syntax of https://phpstan.org/user-guide/output-format#opening-file-in-an-editor even though we would need the second `%` here. (This is due to some phpstan internals, the code ultimately reads `\str_replace(['%file%', '%line%'], ...` But I'd say having an *identical* `editorUrl` syntax between Codeception and phpstan by far outweighs the "cost" of some unneeded `%` characters... ;-) --- src/Codeception/Subscriber/Console.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Subscriber/Console.php b/src/Codeception/Subscriber/Console.php index ba54264eaf..1a7b6c3872 100644 --- a/src/Codeception/Subscriber/Console.php +++ b/src/Codeception/Subscriber/Console.php @@ -356,8 +356,23 @@ public function printFail(FailEvent $e) $this->output->write($e->getCount() . ") "); $this->writeCurrentTest($failedTest, false); $this->output->writeln(''); + + // Clickable `editorUrl`: + if (isset($this->options['editorUrl']) and is_string($this->options['editorUrl'])) { + $filePath = codecept_absolute_path(Descriptor::getTestFileName($failedTest)); + $message = str_replace('%%file%%', $filePath, $this->options['editorUrl']); + $line = 0; + foreach ($fail->getTrace() as $trace) { + if (isset($trace['file']) and $filePath === $trace['file'] and isset($trace['line'])) { + $line = $trace['line']; + } + } + $message = str_replace(['%%file%%', '%%line%%'], [$filePath, $line], $this->options['editorUrl']); + } else { + $message = codecept_relative_path(Descriptor::getTestFullName($failedTest)); + } $this->message(" Test ") - ->append(codecept_relative_path(Descriptor::getTestFullName($failedTest))) + ->append($message) ->write(); if ($failedTest instanceof ScenarioDriven) {