Skip to content

Commit bac0903

Browse files
xurshudyanXurshudyan
andauthored
Fix: always restore original dispatcher in fakeFor and fakeExceptFor (#56189)
Co-authored-by: Xurshudyan <v.khurshudyan@aico.swiss>
1 parent 92463ff commit bac0903

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Illuminate/Support/Facades/Event.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ public static function fakeFor(callable $callable, array $eventsToFake = [])
8989

9090
static::fake($eventsToFake);
9191

92-
return tap($callable(), function () use ($originalDispatcher) {
92+
try {
93+
return $callable();
94+
} finally {
9395
static::swap($originalDispatcher);
9496

9597
Model::setEventDispatcher($originalDispatcher);
9698
Cache::refreshEventDispatcher();
97-
});
99+
}
98100
}
99101

100102
/**
@@ -110,12 +112,14 @@ public static function fakeExceptFor(callable $callable, array $eventsToAllow =
110112

111113
static::fakeExcept($eventsToAllow);
112114

113-
return tap($callable(), function () use ($originalDispatcher) {
115+
try {
116+
return $callable();
117+
} finally {
114118
static::swap($originalDispatcher);
115119

116120
Model::setEventDispatcher($originalDispatcher);
117121
Cache::refreshEventDispatcher();
118-
});
122+
}
119123
}
120124

121125
/**

0 commit comments

Comments
 (0)