|
135 | 135 | // Different errors should have different signatures
|
136 | 136 | expect($formatted1->signature)->not->toBe($formatted2->signature);
|
137 | 137 | });
|
| 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> <vendor frame></summary>') |
| 192 | + ->toContain('vendor/laravel/framework/src/Testing.php') |
| 193 | + ->toContain('vendor/another/package/src/File.php'); |
| 194 | +}); |
0 commit comments