Skip to content

Commit 2d21582

Browse files
committed
wip
1 parent c10efb9 commit 2d21582

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/GithubIssueFormatterTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,60 @@
135135
// Different errors should have different signatures
136136
expect($formatted1->signature)->not->toBe($formatted2->signature);
137137
});
138+
139+
test('it formats stack traces with collapsible vendor frames', function () {
140+
$formatter = new GithubIssueFormatter;
141+
142+
$exception = new Exception('Test exception');
143+
$reflection = new ReflectionClass($exception);
144+
$traceProperty = $reflection->getProperty('trace');
145+
$traceProperty->setAccessible(true);
146+
147+
// Set a custom stack trace with both vendor and application frames
148+
$traceProperty->setValue($exception, [
149+
[
150+
'file' => base_path('app/Http/Controllers/TestController.php'),
151+
'line' => 25,
152+
'function' => 'testMethod',
153+
'class' => 'TestController',
154+
],
155+
[
156+
'file' => base_path('vendor/laravel/framework/src/Testing.php'),
157+
'line' => 50,
158+
'function' => 'vendorMethod',
159+
'class' => 'VendorClass',
160+
],
161+
[
162+
'file' => base_path('vendor/another/package/src/File.php'),
163+
'line' => 100,
164+
'function' => 'anotherVendorMethod',
165+
'class' => 'AnotherVendorClass',
166+
],
167+
[
168+
'file' => base_path('app/Services/TestService.php'),
169+
'line' => 30,
170+
'function' => 'serviceMethod',
171+
'class' => 'TestService',
172+
],
173+
]);
174+
175+
$record = new LogRecord(
176+
datetime: new DateTimeImmutable,
177+
channel: 'test',
178+
level: Level::Error,
179+
message: 'Error occurred',
180+
context: ['exception' => $exception],
181+
extra: []
182+
);
183+
184+
$formatted = $formatter->format($record);
185+
186+
// Verify that app frames are directly visible
187+
expect($formatted->body)
188+
->toContain('app/Http/Controllers/TestController.php')
189+
->toContain('app/Services/TestService.php')
190+
// Verify that vendor frames are wrapped in details tags
191+
->toContain('<details><summary> &lt;vendor frame&gt;</summary>')
192+
->toContain('vendor/laravel/framework/src/Testing.php')
193+
->toContain('vendor/another/package/src/File.php');
194+
});

0 commit comments

Comments
 (0)