@@ -45,9 +45,7 @@ class MailFake implements Factory, Mailer, MailQueue
45
45
*/
46
46
public function assertSent ($ mailable , $ callback = null )
47
47
{
48
- if ($ mailable instanceof Closure) {
49
- [$ mailable , $ callback ] = [$ this ->firstClosureParameterType ($ mailable ), $ mailable ];
50
- }
48
+ [$ mailable , $ callback ] = $ this ->prepareMailableAndCallback ($ mailable , $ callback );
51
49
52
50
if (is_numeric ($ callback )) {
53
51
return $ this ->assertSentTimes ($ mailable , $ callback );
@@ -85,12 +83,14 @@ protected function assertSentTimes($mailable, $times = 1)
85
83
/**
86
84
* Determine if a mailable was not sent based on a truth-test callback.
87
85
*
88
- * @param string $mailable
86
+ * @param string|\Closure $mailable
89
87
* @param callable|null $callback
90
88
* @return void
91
89
*/
92
90
public function assertNotSent ($ mailable , $ callback = null )
93
91
{
92
+ [$ mailable , $ callback ] = $ this ->prepareMailableAndCallback ($ mailable , $ callback );
93
+
94
94
PHPUnit::assertCount (
95
95
0 , $ this ->sent ($ mailable , $ callback ),
96
96
"The unexpected [ {$ mailable }] mailable was sent. "
@@ -120,9 +120,7 @@ public function assertNothingSent()
120
120
*/
121
121
public function assertQueued ($ mailable , $ callback = null )
122
122
{
123
- if ($ mailable instanceof Closure) {
124
- [$ mailable , $ callback ] = [$ this ->firstClosureParameterType ($ mailable ), $ mailable ];
125
- }
123
+ [$ mailable , $ callback ] = $ this ->prepareMailableAndCallback ($ mailable , $ callback );
126
124
127
125
if (is_numeric ($ callback )) {
128
126
return $ this ->assertQueuedTimes ($ mailable , $ callback );
@@ -154,12 +152,14 @@ protected function assertQueuedTimes($mailable, $times = 1)
154
152
/**
155
153
* Determine if a mailable was not queued based on a truth-test callback.
156
154
*
157
- * @param string $mailable
155
+ * @param string|\Closure $mailable
158
156
* @param callable|null $callback
159
157
* @return void
160
158
*/
161
159
public function assertNotQueued ($ mailable , $ callback = null )
162
160
{
161
+ [$ mailable , $ callback ] = $ this ->prepareMailableAndCallback ($ mailable , $ callback );
162
+
163
163
PHPUnit::assertCount (
164
164
0 , $ this ->queued ($ mailable , $ callback ),
165
165
"The unexpected [ {$ mailable }] mailable was queued. "
@@ -183,12 +183,14 @@ public function assertNothingQueued()
183
183
/**
184
184
* Get all of the mailables matching a truth-test callback.
185
185
*
186
- * @param string $mailable
186
+ * @param string|\Closure $mailable
187
187
* @param callable|null $callback
188
188
* @return \Illuminate\Support\Collection
189
189
*/
190
190
public function sent ($ mailable , $ callback = null )
191
191
{
192
+ [$ mailable , $ callback ] = $ this ->prepareMailableAndCallback ($ mailable , $ callback );
193
+
192
194
if (! $ this ->hasSent ($ mailable )) {
193
195
return collect ();
194
196
}
@@ -216,12 +218,14 @@ public function hasSent($mailable)
216
218
/**
217
219
* Get all of the queued mailables matching a truth-test callback.
218
220
*
219
- * @param string $mailable
221
+ * @param string|\Closure $mailable
220
222
* @param callable|null $callback
221
223
* @return \Illuminate\Support\Collection
222
224
*/
223
225
public function queued ($ mailable , $ callback = null )
224
226
{
227
+ [$ mailable , $ callback ] = $ this ->prepareMailableAndCallback ($ mailable , $ callback );
228
+
225
229
if (! $ this ->hasQueued ($ mailable )) {
226
230
return collect ();
227
231
}
@@ -386,4 +390,20 @@ public function failures()
386
390
{
387
391
return [];
388
392
}
393
+
394
+ /**
395
+ * Infer mailable class using reflection if a typehinted closure is passed to assertion.
396
+ *
397
+ * @param string|\Closure $mailable
398
+ * @param callable|null $callback
399
+ * @return array
400
+ */
401
+ protected function prepareMailableAndCallback ($ mailable , $ callback )
402
+ {
403
+ if ($ mailable instanceof Closure) {
404
+ return [$ this ->firstClosureParameterType ($ mailable ), $ mailable ];
405
+ }
406
+
407
+ return [$ mailable , $ callback ];
408
+ }
389
409
}
0 commit comments