33namespace Illuminate \Foundation \Testing \Concerns ;
44
55use Mockery ;
6- use Exception ;
76use Illuminate \Contracts \Bus \Dispatcher as BusDispatcherContract ;
87use Illuminate \Contracts \Events \Dispatcher as EventsDispatcherContract ;
98use Illuminate \Contracts \Notifications \Dispatcher as NotificationDispatcher ;
@@ -57,11 +56,10 @@ public function expectsEvents($events)
5756 $ this ->beforeApplicationDestroyed (function () use ($ events ) {
5857 $ fired = $ this ->getFiredEvents ($ events );
5958
60- if ($ eventsNotFired = array_diff ($ events , $ fired )) {
61- throw new Exception (
62- 'These expected events were not fired: [ ' .implode (', ' , $ eventsNotFired ).'] '
63- );
64- }
59+ $ this ->assertEmpty (
60+ $ eventsNotFired = array_diff ($ events , $ fired ),
61+ 'These expected events were not fired: [ ' .implode (', ' , $ eventsNotFired ).'] '
62+ );
6563 });
6664
6765 return $ this ;
@@ -82,11 +80,10 @@ public function doesntExpectEvents($events)
8280 $ this ->withoutEvents ();
8381
8482 $ this ->beforeApplicationDestroyed (function () use ($ events ) {
85- if ($ fired = $ this ->getFiredEvents ($ events )) {
86- throw new Exception (
87- 'These unexpected events were fired: [ ' .implode (', ' , $ fired ).'] '
88- );
89- }
83+ $ this ->assertEmpty (
84+ $ fired = $ this ->getFiredEvents ($ events ),
85+ 'These unexpected events were fired: [ ' .implode (', ' , $ fired ).'] '
86+ );
9087 });
9188
9289 return $ this ;
@@ -138,11 +135,10 @@ protected function expectsJobs($jobs)
138135 $ this ->beforeApplicationDestroyed (function () use ($ jobs ) {
139136 $ dispatched = $ this ->getDispatchedJobs ($ jobs );
140137
141- if ($ jobsNotDispatched = array_diff ($ jobs , $ dispatched )) {
142- throw new Exception (
143- 'These expected jobs were not dispatched: [ ' .implode (', ' , $ jobsNotDispatched ).'] '
144- );
145- }
138+ $ this ->assertEmpty (
139+ $ jobsNotDispatched = array_diff ($ jobs , $ dispatched ),
140+ 'These expected jobs were not dispatched: [ ' .implode (', ' , $ jobsNotDispatched ).'] '
141+ );
146142 });
147143
148144 return $ this ;
@@ -163,11 +159,10 @@ protected function doesntExpectJobs($jobs)
163159 $ this ->withoutJobs ();
164160
165161 $ this ->beforeApplicationDestroyed (function () use ($ jobs ) {
166- if ($ dispatched = $ this ->getDispatchedJobs ($ jobs )) {
167- throw new Exception (
168- 'These unexpected jobs were dispatched: [ ' .implode (', ' , $ dispatched ).'] '
169- );
170- }
162+ $ this ->assertEmpty (
163+ $ dispatched = $ this ->getDispatchedJobs ($ jobs ),
164+ 'These unexpected jobs were dispatched: [ ' .implode (', ' , $ dispatched ).'] '
165+ );
171166 });
172167
173168 return $ this ;
@@ -280,9 +275,7 @@ protected function expectsNotification($notifiable, $notification)
280275 }
281276 }
282277
283- throw new Exception (
284- 'The following expected notification were not dispatched: [ ' .$ notification .'] '
285- );
278+ $ this ->fail ('The following expected notification were not dispatched: [ ' .$ notification .'] ' );
286279 });
287280
288281 return $ this ;
0 commit comments