Skip to content

Commit 1f72d81

Browse files
committed
fix: ensure eloquent events fire in test environment
Add clearBootedModels call in setUp to force models to re-boot after application initialization, ensuring event handlers are properly wired to the event dispatcher
1 parent 5da0db9 commit 1f72d81

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/TestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ protected function setUp(): void
4343
{
4444
parent::setUp();
4545

46+
// Clear booted models to ensure event listeners are properly registered
47+
// This fixes an issue where models booted during test environment setup
48+
// don't have their Eloquent events properly wired to the event dispatcher
49+
Post::clearBootedModels();
50+
User::clearBootedModels();
51+
4652
Factory::guessFactoryNamesUsing(
4753
fn (string $modelName): string => match ($modelName) {
4854
User::class => UserFactory::class,

0 commit comments

Comments
 (0)