Skip to content

Commit

Permalink
Adding clickable editorUrl from codeception.yml
Browse files Browse the repository at this point in the history
Closes Codeception#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... ;-)
  • Loading branch information
ThomasLandauer committed Oct 8, 2021
1 parent ec4820f commit 4dd4839
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Codeception/Subscriber/Console.php
Expand Up @@ -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("<error> Test </error> ")
->append(codecept_relative_path(Descriptor::getTestFullName($failedTest)))
->append($message)
->write();

if ($failedTest instanceof ScenarioDriven) {
Expand Down

0 comments on commit 4dd4839

Please sign in to comment.