Permalink
Browse files

Fix last line excerpt not retrievable.

The line number needs to be decremented before testing for existence,
otherwise the last line number would be out of bounds.
  • Loading branch information...
ndm2
ndm2 committed Jun 23, 2017
1 parent 4319fd4 commit 1539a52ff760ca37360ac19b6e4b1c24054b0e47
Showing with 8 additions and 1 deletion.
  1. +1 −1 src/Error/Debugger.php
  2. +7 −0 tests/TestCase/Error/DebuggerTest.php
View
@@ -421,10 +421,10 @@ public static function excerpt($file, $line, $context = 2)
if (strpos($data, "\n") !== false) {
$data = explode("\n", $data);
}
$line--;
if (!isset($data[$line])) {
return $lines;
}
$line--;
for ($i = $line - $context; $i < $line + $context + 1; $i++) {
if (!isset($data[$i])) {
continue;
@@ -129,6 +129,13 @@ public function testExcerpt()
$this->assertContains('Debugger', $result[5]);
$this->assertContains('excerpt', $result[5]);
$this->assertContains('__FILE__', $result[5]);
$result = Debugger::excerpt(__FILE__, 1, 2);
$this->assertCount(3, $result);
$lastLine = count(explode("\n", file_get_contents(__FILE__)));
$result = Debugger::excerpt(__FILE__, $lastLine, 2);
$this->assertCount(3, $result);
}
/**

0 comments on commit 1539a52

Please sign in to comment.