Skip to content

Commit c9af3bc

Browse files
[12.x] - Improved assertion message for dispatchedTimes methods (#56544)
* add methods * adjust * adjust messages
1 parent 0dba49d commit c9af3bc

File tree

8 files changed

+54
-23
lines changed

8 files changed

+54
-23
lines changed

src/Illuminate/Support/Testing/Fakes/BusFake.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Contracts\Bus\QueueingDispatcher;
1010
use Illuminate\Support\Arr;
1111
use Illuminate\Support\Collection;
12+
use Illuminate\Support\Str;
1213
use Illuminate\Support\Traits\ReflectsClosures;
1314
use PHPUnit\Framework\Assert as PHPUnit;
1415
use RuntimeException;
@@ -165,7 +166,11 @@ public function assertDispatchedTimes($command, $times = 1)
165166

166167
PHPUnit::assertSame(
167168
$times, $count,
168-
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
169+
sprintf(
170+
"The expected [{$command}] job was pushed {$count} %s instead of {$times} %s.",
171+
Str::plural('time', $count),
172+
Str::plural('time', $times)
173+
)
169174
);
170175
}
171176

@@ -244,7 +249,11 @@ public function assertDispatchedSyncTimes($command, $times = 1)
244249

245250
PHPUnit::assertSame(
246251
$times, $count,
247-
"The expected [{$command}] job was synchronously pushed {$count} times instead of {$times} times."
252+
sprintf(
253+
"The expected [{$command}] job was synchronously pushed {$count} %s instead of {$times} %s.",
254+
Str::plural('time', $count),
255+
Str::plural('time', $times)
256+
)
248257
);
249258
}
250259

@@ -309,7 +318,11 @@ public function assertDispatchedAfterResponseTimes($command, $times = 1)
309318

310319
PHPUnit::assertSame(
311320
$times, $count,
312-
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
321+
sprintf(
322+
"The expected [{$command}] job was pushed {$count} %s instead of {$times} %s.",
323+
Str::plural('time', $count),
324+
Str::plural('time', $times)
325+
)
313326
);
314327
}
315328

src/Illuminate/Support/Testing/Fakes/EventFake.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ public function assertDispatchedTimes($event, $times = 1)
172172

173173
PHPUnit::assertSame(
174174
$times, $count,
175-
"The expected [{$event}] event was dispatched {$count} times instead of {$times} times."
175+
sprintf(
176+
"The expected [{$event}] event was dispatched {$count} %s instead of {$times} %s.",
177+
Str::plural('time', $count),
178+
Str::plural('time', $times)
179+
)
176180
);
177181
}
178182

src/Illuminate/Support/Testing/Fakes/MailFake.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Mail\MailManager;
1212
use Illuminate\Support\Arr;
1313
use Illuminate\Support\Collection;
14+
use Illuminate\Support\Str;
1415
use Illuminate\Support\Traits\ForwardsCalls;
1516
use Illuminate\Support\Traits\ReflectsClosures;
1617
use PHPUnit\Framework\Assert as PHPUnit;
@@ -107,7 +108,11 @@ protected function assertSentTimes($mailable, $times = 1)
107108

108109
PHPUnit::assertSame(
109110
$times, $count,
110-
"The expected [{$mailable}] mailable was sent {$count} times instead of {$times} times."
111+
sprintf(
112+
"The expected [{$mailable}] mailable was sent {$count} %s instead of {$times} %s.",
113+
Str::plural('time', $count),
114+
Str::plural('time', $times)
115+
)
111116
);
112117
}
113118

@@ -226,7 +231,11 @@ protected function assertQueuedTimes($mailable, $times = 1)
226231

227232
PHPUnit::assertSame(
228233
$times, $count,
229-
"The expected [{$mailable}] mailable was queued {$count} times instead of {$times} times."
234+
sprintf(
235+
"The expected [{$mailable}] mailable was queued {$count} %s instead of {$times} %s.",
236+
Str::plural('time', $count),
237+
Str::plural('time', $times)
238+
)
230239
);
231240
}
232241

src/Illuminate/Support/Testing/Fakes/QueueFake.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Queue\CallQueuedClosure;
1010
use Illuminate\Queue\QueueManager;
1111
use Illuminate\Support\Collection;
12+
use Illuminate\Support\Str;
1213
use Illuminate\Support\Traits\ReflectsClosures;
1314
use PHPUnit\Framework\Assert as PHPUnit;
1415

@@ -126,7 +127,11 @@ protected function assertPushedTimes($job, $times = 1)
126127

127128
PHPUnit::assertSame(
128129
$times, $count,
129-
"The expected [{$job}] job was pushed {$count} times instead of {$times} times."
130+
sprintf(
131+
"The expected [{$job}] job was pushed {$count} %s instead of {$times} %s.",
132+
Str::plural('time', $count),
133+
Str::plural('time', $times)
134+
)
130135
);
131136
}
132137

tests/Support/SupportTestingBusFakeTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testAssertDispatchedWithCallbackInt()
146146
$this->fake->assertDispatched(BusJobStub::class, 1);
147147
$this->fail();
148148
} catch (ExpectationFailedException $e) {
149-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage());
149+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 time.', $e->getMessage());
150150
}
151151

152152
$this->fake->assertDispatched(BusJobStub::class, 2);
@@ -161,7 +161,7 @@ public function testAssertDispatchedAfterResponseWithCallbackInt()
161161
$this->fake->assertDispatchedAfterResponse(BusJobStub::class, 1);
162162
$this->fail();
163163
} catch (ExpectationFailedException $e) {
164-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage());
164+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 time.', $e->getMessage());
165165
}
166166

167167
$this->fake->assertDispatchedAfterResponse(BusJobStub::class, 2);
@@ -176,7 +176,7 @@ public function testAssertDispatchedSyncWithCallbackInt()
176176
$this->fake->assertDispatchedSync(BusJobStub::class, 1);
177177
$this->fail();
178178
} catch (ExpectationFailedException $e) {
179-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 times.', $e->getMessage());
179+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 time.', $e->getMessage());
180180
}
181181

182182
$this->fake->assertDispatchedSync(BusJobStub::class, 2);
@@ -240,7 +240,7 @@ public function testAssertDispatchedAfterResponseTimesWithCallbackFunction()
240240
}, 2);
241241
$this->fail();
242242
} catch (ExpectationFailedException $e) {
243-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was pushed 1 times instead of 2 times.', $e->getMessage());
243+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was pushed 1 time instead of 2 times.', $e->getMessage());
244244
}
245245

246246
$this->fake->assertDispatchedAfterResponseTimes(function (OtherBusJobStub $job) {
@@ -284,7 +284,7 @@ public function testAssertDispatchedOnce()
284284
$this->fake->assertDispatchedOnce(BusJobStub::class);
285285
$this->fail();
286286
} catch (ExpectationFailedException $e) {
287-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage());
287+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 time.', $e->getMessage());
288288
}
289289

290290
$this->fake->assertDispatchedTimes(BusJobStub::class, 2);
@@ -299,7 +299,7 @@ public function testAssertDispatchedTimes()
299299
$this->fake->assertDispatchedTimes(BusJobStub::class, 1);
300300
$this->fail();
301301
} catch (ExpectationFailedException $e) {
302-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage());
302+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 time.', $e->getMessage());
303303
}
304304

305305
$this->fake->assertDispatchedTimes(BusJobStub::class, 2);
@@ -317,7 +317,7 @@ public function testAssertDispatchedTimesWithCallbackFunction()
317317
}, 2);
318318
$this->fail();
319319
} catch (ExpectationFailedException $e) {
320-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was pushed 1 times instead of 2 times.', $e->getMessage());
320+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was pushed 1 time instead of 2 times.', $e->getMessage());
321321
}
322322

323323
$this->fake->assertDispatchedTimes(function (OtherBusJobStub $job) {
@@ -338,7 +338,7 @@ public function testAssertDispatchedAfterResponseTimes()
338338
$this->fake->assertDispatchedAfterResponseTimes(BusJobStub::class, 1);
339339
$this->fail();
340340
} catch (ExpectationFailedException $e) {
341-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 times.', $e->getMessage());
341+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was pushed 2 times instead of 1 time.', $e->getMessage());
342342
}
343343

344344
$this->fake->assertDispatchedAfterResponseTimes(BusJobStub::class, 2);
@@ -353,7 +353,7 @@ public function testAssertDispatchedSyncTimes()
353353
$this->fake->assertDispatchedSyncTimes(BusJobStub::class, 1);
354354
$this->fail();
355355
} catch (ExpectationFailedException $e) {
356-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 times.', $e->getMessage());
356+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\BusJobStub] job was synchronously pushed 2 times instead of 1 time.', $e->getMessage());
357357
}
358358

359359
$this->fake->assertDispatchedSyncTimes(BusJobStub::class, 2);
@@ -371,7 +371,7 @@ public function testAssertDispatchedSyncTimesWithCallbackFunction()
371371
}, 2);
372372
$this->fail();
373373
} catch (ExpectationFailedException $e) {
374-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was synchronously pushed 1 times instead of 2 times.', $e->getMessage());
374+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was synchronously pushed 1 time instead of 2 times.', $e->getMessage());
375375
}
376376

377377
$this->fake->assertDispatchedSyncTimes(function (OtherBusJobStub $job) {

tests/Support/SupportTestingEventFakeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testAssertDispatchedWithCallbackInt()
7070
$this->fake->assertDispatched(EventStub::class, 1);
7171
$this->fail();
7272
} catch (ExpectationFailedException $e) {
73-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.', $e->getMessage());
73+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 time.', $e->getMessage());
7474
}
7575

7676
$this->fake->assertDispatched(EventStub::class, 2);
@@ -85,7 +85,7 @@ public function testAssertDispatchedOnce()
8585
$this->fake->assertDispatchedOnce(EventStub::class);
8686
$this->fail();
8787
} catch (ExpectationFailedException $e) {
88-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.', $e->getMessage());
88+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 time.', $e->getMessage());
8989
}
9090

9191
$this->fake->assertDispatchedTimes(EventStub::class, 2);
@@ -100,7 +100,7 @@ public function testAssertDispatchedTimes()
100100
$this->fake->assertDispatchedTimes(EventStub::class, 1);
101101
$this->fail();
102102
} catch (ExpectationFailedException $e) {
103-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 times.', $e->getMessage());
103+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\EventStub] event was dispatched 2 times instead of 1 time.', $e->getMessage());
104104
}
105105

106106
$this->fake->assertDispatchedTimes(EventStub::class, 2);

tests/Support/SupportTestingMailFakeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function testAssertSentTimes()
182182
$this->fake->assertSent(MailableStub::class, 1);
183183
$this->fail();
184184
} catch (ExpectationFailedException $e) {
185-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was sent 2 times instead of 1 times.', $e->getMessage());
185+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was sent 2 times instead of 1 time.', $e->getMessage());
186186
}
187187

188188
$this->fake->assertSent(MailableStub::class, 2);
@@ -254,7 +254,7 @@ public function testAssertQueuedTimes()
254254
$this->fake->assertQueued(MailableStub::class, 1);
255255
$this->fail();
256256
} catch (ExpectationFailedException $e) {
257-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was queued 2 times instead of 1 times.', $e->getMessage());
257+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was queued 2 times instead of 1 time.', $e->getMessage());
258258
}
259259

260260
$this->fake->assertQueued(MailableStub::class, 2);

tests/Support/SupportTestingQueueFakeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testAssertPushedTimes()
171171
$this->fake->assertPushed(JobStub::class, 1);
172172
$this->fail();
173173
} catch (ExpectationFailedException $e) {
174-
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobStub] job was pushed 2 times instead of 1 times.', $e->getMessage());
174+
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\JobStub] job was pushed 2 times instead of 1 time.', $e->getMessage());
175175
}
176176

177177
$this->fake->assertPushed(JobStub::class, 2);

0 commit comments

Comments
 (0)