From 685b3331e7758df0f5889f0a8ca5735e5ee4e1a0 Mon Sep 17 00:00:00 2001 From: Xurshudyan Date: Tue, 1 Jul 2025 20:55:09 +0400 Subject: [PATCH] Fix: always restore original dispatcher in fakeFor and fakeExceptFor --- src/Illuminate/Support/Facades/Event.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Support/Facades/Event.php b/src/Illuminate/Support/Facades/Event.php index 7200978c3baf..09f26875ddc4 100755 --- a/src/Illuminate/Support/Facades/Event.php +++ b/src/Illuminate/Support/Facades/Event.php @@ -89,12 +89,14 @@ public static function fakeFor(callable $callable, array $eventsToFake = []) static::fake($eventsToFake); - return tap($callable(), function () use ($originalDispatcher) { + try { + return $callable(); + } finally { static::swap($originalDispatcher); Model::setEventDispatcher($originalDispatcher); Cache::refreshEventDispatcher(); - }); + } } /** @@ -110,12 +112,14 @@ public static function fakeExceptFor(callable $callable, array $eventsToAllow = static::fakeExcept($eventsToAllow); - return tap($callable(), function () use ($originalDispatcher) { + try { + return $callable(); + } finally { static::swap($originalDispatcher); Model::setEventDispatcher($originalDispatcher); Cache::refreshEventDispatcher(); - }); + } } /**