Skip to content

Commit 2f0336c

Browse files
sebastiandedeynetaylorotwell
authored andcommitted
[5.4] Add PHPUnit failures to MocksApplicationServices (#18774)
* Add PHPUnit failures to MocksApplicationServices * CS
1 parent 39d029d commit 2f0336c

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php

+17-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Illuminate\Foundation\Testing\Concerns;
44

55
use Mockery;
6-
use Exception;
76
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
87
use Illuminate\Contracts\Events\Dispatcher as EventsDispatcherContract;
98
use 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

Comments
 (0)