Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding clickable editorUrl from codeception.yml #6261

Merged
merged 13 commits into from Dec 21, 2021
13 changes: 10 additions & 3 deletions src/Codeception/Step.php
Expand Up @@ -79,10 +79,17 @@ public function getAction()
return $this->action;
}

public function getLine()
public function getFilePath()
Naktibalda marked this conversation as resolved.
Show resolved Hide resolved
{
if ($this->line && $this->file) {
return codecept_relative_path($this->file) . ':' . $this->line;
if ($this->file) {
return codecept_relative_path($this->file);
}
}

public function getLineNumber()
{
if ($this->line) {
return $this->line;
}
}

Expand Down
39 changes: 34 additions & 5 deletions src/Codeception/Subscriber/Console.php
Expand Up @@ -356,8 +356,22 @@ 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'])) {
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
$filePath = codecept_absolute_path(Descriptor::getTestFileName($failedTest));
$line = 1;
foreach ($fail->getTrace() as $trace) {
if (isset($trace['file']) and $filePath === $trace['file'] and isset($trace['line'])) {
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
$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)
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
->write();

if ($failedTest instanceof ScenarioDriven) {
Expand Down Expand Up @@ -492,7 +506,14 @@ public function printExceptionTrace($e)
$message->writeln();
continue;
}
$message->append($step['file'] . ':' . $step['line']);

// Clickable `editorUrl`:
if (isset($this->options['editorUrl']) and is_string($this->options['editorUrl'])) {
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
$lineString = str_replace(['%%file%%', '%%line%%'], [$step['file'], $step['line']], $this->options['editorUrl']);
} else {
$lineString = $step['file'] . ':' . $step['line'];
}
$message->append($lineString);
$message->writeln();
}

Expand Down Expand Up @@ -536,9 +557,17 @@ public function printScenarioTrace(ScenarioDriven $failedTest)
$message->style('bold');
}

$line = $step->getLine();
if ($line and (!$step instanceof Comment)) {
$message->append(" at <info>$line</info>");
if (!$step instanceof Comment) {
$filePath = $step->getFilePath();
if ($filePath) {
// Clickable `editorUrl`:
if (isset($this->options['editorUrl']) and is_string($this->options['editorUrl'])) {
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
$lineString = str_replace(['%%file%%', '%%line%%'], [codecept_absolute_path($step->getFilePath()), $step->getLineNumber()], $this->options['editorUrl']);
} else {
$lineString = $step->getFilePath() . ':' . $step->getLineNumber();
}
}
$message->append(" at <info>$lineString</info>");
ThomasLandauer marked this conversation as resolved.
Show resolved Hide resolved
}

$stepNumber--;
Expand Down