Skip to content

Commit

Permalink
Return empty stack frame context for Unknown files
Browse files Browse the repository at this point in the history
  • Loading branch information
victorstanciu committed Nov 15, 2018
1 parent 6372b1b commit bc05017
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/StackTrace/StackFrameContextExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class StackFrameContextExtractor
*/
public function getContext($file, $line, $contextLines = 15)
{
if ($file === "Unknown") {
return [];
}
if (!file_exists($file)) {
throw new RuntimeException();
}
Expand Down
7 changes: 6 additions & 1 deletion tests/StackTrace/StackFrameContextExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function testWhenFileDoesNotExist_exceptionIsThrown()
$this->extractor->getContext("/missing/file", 0, 5);
}

public function testWhenFileIsUnknownEmptyArrayIsReturned()
{
$this->assertEquals([], $this->extractor->getContext("Unknown", 0));
}

public function testWhenNegativeLineNumberProvided_exceptionIsThrown()
{
$this->expectException(InvalidArgumentException::class);
Expand Down Expand Up @@ -62,7 +67,7 @@ public function testFirstLines()
3 => "Line 3",
4 => "Line 4",
5 => "Line 5",
6 => "Line 6"
6 => "Line 6",
], $this->getContext(1, 5));
}

Expand Down

0 comments on commit bc05017

Please sign in to comment.