Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jan 10, 2025
1 parent c10efb9 commit 2d21582
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/GithubIssueFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,60 @@
// Different errors should have different signatures
expect($formatted1->signature)->not->toBe($formatted2->signature);
});

test('it formats stack traces with collapsible vendor frames', function () {
$formatter = new GithubIssueFormatter;

$exception = new Exception('Test exception');
$reflection = new ReflectionClass($exception);
$traceProperty = $reflection->getProperty('trace');
$traceProperty->setAccessible(true);

// Set a custom stack trace with both vendor and application frames
$traceProperty->setValue($exception, [
[
'file' => base_path('app/Http/Controllers/TestController.php'),
'line' => 25,
'function' => 'testMethod',
'class' => 'TestController',
],
[
'file' => base_path('vendor/laravel/framework/src/Testing.php'),
'line' => 50,
'function' => 'vendorMethod',
'class' => 'VendorClass',
],
[
'file' => base_path('vendor/another/package/src/File.php'),
'line' => 100,
'function' => 'anotherVendorMethod',
'class' => 'AnotherVendorClass',
],
[
'file' => base_path('app/Services/TestService.php'),
'line' => 30,
'function' => 'serviceMethod',
'class' => 'TestService',
],
]);

$record = new LogRecord(
datetime: new DateTimeImmutable,
channel: 'test',
level: Level::Error,
message: 'Error occurred',
context: ['exception' => $exception],
extra: []
);

$formatted = $formatter->format($record);

// Verify that app frames are directly visible
expect($formatted->body)
->toContain('app/Http/Controllers/TestController.php')
->toContain('app/Services/TestService.php')
// Verify that vendor frames are wrapped in details tags
->toContain('<details><summary> &lt;vendor frame&gt;</summary>')
->toContain('vendor/laravel/framework/src/Testing.php')
->toContain('vendor/another/package/src/File.php');
});

0 comments on commit 2d21582

Please sign in to comment.