From 1f827ef887f94654d1ee83f1c9a6a87caef34faf Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2024 11:59:57 -0500 Subject: [PATCH 1/2] add function to get faked events this function will return an array of all Events that have been faked. this can be helpful when originally writing the tests to get a grasp of which events you may need to intercept. both the `QueueFake` and `NotificationFake` have similar methods to let you see what has been intercepted by the fake. https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/Testing/Fakes/QueueFake.php#L512 https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/Testing/Fakes/NotificationFake.php#L357 --- src/Illuminate/Support/Testing/Fakes/EventFake.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Illuminate/Support/Testing/Fakes/EventFake.php b/src/Illuminate/Support/Testing/Fakes/EventFake.php index 4a4fc7c5b22d..60f26a791300 100644 --- a/src/Illuminate/Support/Testing/Fakes/EventFake.php +++ b/src/Illuminate/Support/Testing/Fakes/EventFake.php @@ -59,6 +59,16 @@ public function __construct(Dispatcher $dispatcher, $eventsToFake = []) $this->eventsToFake = Arr::wrap($eventsToFake); } + /** + * Get the events that have been pushed. + * + * @return array + */ + public function pushedEvents() + { + return $this->events; + } + /** * Specify the events that should be dispatched instead of faked. * From 3a15f62cfb994ec13eeb99b2249f9bc1e083db48 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Apr 2024 09:20:58 -0500 Subject: [PATCH 2/2] Update EventFake.php --- .../Support/Testing/Fakes/EventFake.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Support/Testing/Fakes/EventFake.php b/src/Illuminate/Support/Testing/Fakes/EventFake.php index 60f26a791300..e6b956eb8572 100644 --- a/src/Illuminate/Support/Testing/Fakes/EventFake.php +++ b/src/Illuminate/Support/Testing/Fakes/EventFake.php @@ -59,16 +59,6 @@ public function __construct(Dispatcher $dispatcher, $eventsToFake = []) $this->eventsToFake = Arr::wrap($eventsToFake); } - /** - * Get the events that have been pushed. - * - * @return array - */ - public function pushedEvents() - { - return $this->events; - } - /** * Specify the events that should be dispatched instead of faked. * @@ -414,6 +404,16 @@ public function until($event, $payload = []) return $this->dispatch($event, $payload, true); } + /** + * Get the events that have been dispatched. + * + * @return array + */ + public function dispatchedEvents() + { + return $this->events; + } + /** * Handle dynamic method calls to the dispatcher. *