Skip to content

Commit

Permalink
Fix error output line highlighting off by one.
Browse files Browse the repository at this point in the history
The debugger highlights the line before the actual line of error.
  • Loading branch information
ndm2 committed Sep 5, 2017
1 parent 3f9caaa commit eceac7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Error/Debugger.php
Expand Up @@ -792,7 +792,7 @@ public function outputError($data)
$file = $files[1];
}
if ($file) {
$code = static::excerpt($file['file'], $file['line'] - 1, 1);
$code = static::excerpt($file['file'], $file['line'], 1);
}
$trace = static::trace(['start' => $data['start'], 'depth' => '20']);
$insertOpts = ['before' => '{:', 'after' => '}'];
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/Error/DebuggerTest.php
Expand Up @@ -206,6 +206,31 @@ public function testOutputErrorDescriptionEncoding()
$this->assertNotContains('<script>', $result);
}

/**
* Tests that the correct line is being highlighted.
*
* @return void
*/
public function testOutputErrorLineHighlight()
{
Debugger::outputAs('js');

ob_start();
$debugger = Debugger::getInstance();
$data = [
'level' => E_NOTICE,
'code' => E_NOTICE,
'file' => __FILE__,
'line' => __LINE__,
'description' => 'Error description',
'start' => 1
];
$debugger->outputError($data);
$result = ob_get_clean();

$this->assertRegExp('#^\<span class\="code\-highlight"\>.*outputError.*\</span\>$#m', $result);
}

/**
* Tests that changes in output formats using Debugger::output() change the templates used.
*
Expand Down

0 comments on commit eceac7d

Please sign in to comment.