|
398 | 398 | // Different UUIDs in exception message should produce same signature after templating |
399 | 399 | expect($signature2)->toBe($signature1); |
400 | 400 | }); |
| 401 | + |
| 402 | +test('groups errors from same vendor class with different methods', function () { |
| 403 | + // Simulate errors from the same vendor class (DefaultFileRemover) but different methods |
| 404 | + // This tests that vendor frames are normalized to class name only |
| 405 | + |
| 406 | + $exception1 = new \Exception('Disk [tracks] does not have a configured driver.'); |
| 407 | + $reflection1 = new \ReflectionClass($exception1); |
| 408 | + $traceProperty1 = $reflection1->getProperty('trace'); |
| 409 | + $traceProperty1->setAccessible(true); |
| 410 | + $fileProperty1 = $reflection1->getProperty('file'); |
| 411 | + $fileProperty1->setAccessible(true); |
| 412 | + $lineProperty1 = $reflection1->getProperty('line'); |
| 413 | + $lineProperty1->setAccessible(true); |
| 414 | + |
| 415 | + // Set exception file and line |
| 416 | + $fileProperty1->setValue($exception1, base_path('vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php')); |
| 417 | + $lineProperty1->setValue($exception1, 138); |
| 418 | + |
| 419 | + // First error: through removeFromMediaDirectory |
| 420 | + $traceProperty1->setValue($exception1, [ |
| 421 | + [ |
| 422 | + 'file' => base_path('vendor/spatie/laravel-medialibrary/src/Support/FileRemover/DefaultFileRemover.php'), |
| 423 | + 'line' => 38, |
| 424 | + 'function' => 'removeFromMediaDirectory', |
| 425 | + 'class' => 'Spatie\\MediaLibrary\\Support\\FileRemover\\DefaultFileRemover', |
| 426 | + 'type' => '->', |
| 427 | + ], |
| 428 | + [ |
| 429 | + 'file' => base_path('app/Nova/Track.php'), |
| 430 | + 'line' => 128, |
| 431 | + 'function' => 'fieldsForUpdate', |
| 432 | + 'class' => 'App\\Nova\\Track', |
| 433 | + 'type' => '->', |
| 434 | + ], |
| 435 | + ]); |
| 436 | + |
| 437 | + $exception2 = new \Exception('Disk [tracks] does not have a configured driver.'); |
| 438 | + $reflection2 = new \ReflectionClass($exception2); |
| 439 | + $traceProperty2 = $reflection2->getProperty('trace'); |
| 440 | + $traceProperty2->setAccessible(true); |
| 441 | + $fileProperty2 = $reflection2->getProperty('file'); |
| 442 | + $fileProperty2->setAccessible(true); |
| 443 | + $lineProperty2 = $reflection2->getProperty('line'); |
| 444 | + $lineProperty2->setAccessible(true); |
| 445 | + |
| 446 | + // Set exception file and line |
| 447 | + $fileProperty2->setValue($exception2, base_path('vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php')); |
| 448 | + $lineProperty2->setValue($exception2, 138); |
| 449 | + |
| 450 | + // Second error: through removeFromConversionsDirectory |
| 451 | + $traceProperty2->setValue($exception2, [ |
| 452 | + [ |
| 453 | + 'file' => base_path('vendor/spatie/laravel-medialibrary/src/Support/FileRemover/DefaultFileRemover.php'), |
| 454 | + 'line' => 64, |
| 455 | + 'function' => 'removeFromConversionsDirectory', |
| 456 | + 'class' => 'Spatie\\MediaLibrary\\Support\\FileRemover\\DefaultFileRemover', |
| 457 | + 'type' => '->', |
| 458 | + ], |
| 459 | + [ |
| 460 | + 'file' => base_path('app/Nova/Track.php'), |
| 461 | + 'line' => 128, |
| 462 | + 'function' => 'fieldsForUpdate', |
| 463 | + 'class' => 'App\\Nova\\Track', |
| 464 | + 'type' => '->', |
| 465 | + ], |
| 466 | + ]); |
| 467 | + |
| 468 | + $exception3 = new \Exception('Disk [tracks] does not have a configured driver.'); |
| 469 | + $reflection3 = new \ReflectionClass($exception3); |
| 470 | + $traceProperty3 = $reflection3->getProperty('trace'); |
| 471 | + $traceProperty3->setAccessible(true); |
| 472 | + $fileProperty3 = $reflection3->getProperty('file'); |
| 473 | + $fileProperty3->setAccessible(true); |
| 474 | + $lineProperty3 = $reflection3->getProperty('line'); |
| 475 | + $lineProperty3->setAccessible(true); |
| 476 | + |
| 477 | + // Set exception file and line |
| 478 | + $fileProperty3->setValue($exception3, base_path('vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php')); |
| 479 | + $lineProperty3->setValue($exception3, 138); |
| 480 | + |
| 481 | + // Third error: through removeFromResponsiveImagesDirectory |
| 482 | + $traceProperty3->setValue($exception3, [ |
| 483 | + [ |
| 484 | + 'file' => base_path('vendor/spatie/laravel-medialibrary/src/Support/FileRemover/DefaultFileRemover.php'), |
| 485 | + 'line' => 96, |
| 486 | + 'function' => 'removeFromResponsiveImagesDirectory', |
| 487 | + 'class' => 'Spatie\\MediaLibrary\\Support\\FileRemover\\DefaultFileRemover', |
| 488 | + 'type' => '->', |
| 489 | + ], |
| 490 | + [ |
| 491 | + 'file' => base_path('app/Nova/Track.php'), |
| 492 | + 'line' => 128, |
| 493 | + 'function' => 'fieldsForUpdate', |
| 494 | + 'class' => 'App\\Nova\\Track', |
| 495 | + 'type' => '->', |
| 496 | + ], |
| 497 | + ]); |
| 498 | + |
| 499 | + $record1 = createLogRecord('Test', [ |
| 500 | + 'request' => [ |
| 501 | + 'route' => ['name' => 'nova.api.generated::t9axneyGDK4KlTRT'], |
| 502 | + 'method' => 'PUT', |
| 503 | + ], |
| 504 | + ], exception: $exception1); |
| 505 | + |
| 506 | + $record2 = createLogRecord('Test', [ |
| 507 | + 'request' => [ |
| 508 | + 'route' => ['name' => 'nova.api.generated::t9axneyGDK4KlTRT'], |
| 509 | + 'method' => 'PUT', |
| 510 | + ], |
| 511 | + ], exception: $exception2); |
| 512 | + |
| 513 | + $record3 = createLogRecord('Test', [ |
| 514 | + 'request' => [ |
| 515 | + 'route' => ['name' => 'nova.api.generated::t9axneyGDK4KlTRT'], |
| 516 | + 'method' => 'PUT', |
| 517 | + ], |
| 518 | + ], exception: $exception3); |
| 519 | + |
| 520 | + $signature1 = $this->generator->generate($record1); |
| 521 | + $signature2 = $this->generator->generate($record2); |
| 522 | + $signature3 = $this->generator->generate($record3); |
| 523 | + |
| 524 | + // All three errors should produce the same signature despite different vendor methods |
| 525 | + // because they're from the same vendor class and have the same in-app frames |
| 526 | + expect($signature2)->toBe($signature1); |
| 527 | + expect($signature3)->toBe($signature1); |
| 528 | +}); |
0 commit comments