Skip to content

Commit d476191

Browse files
[10.x] Add assertCount test helper (#49609)
* Add assertCount method * apply StyleCI * Update QueueFake.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0807344 commit d476191

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ public function assertNotPushed($job, $callback = null)
278278
);
279279
}
280280

281+
/**
282+
* Assert the total count of jobs that were pushed.
283+
*
284+
* @param int $expectedCount
285+
* @return void
286+
*/
287+
public function assertCount($expectedCount)
288+
{
289+
$actualCount = collect($this->jobs)->flatten(1)->count();
290+
291+
PHPUnit::assertSame(
292+
$expectedCount, $actualCount,
293+
"Expected {$expectedCount} jobs to be pushed, but found {$actualCount} instead."
294+
);
295+
}
296+
281297
/**
282298
* Assert that no jobs were pushed.
283299
*

tests/Support/SupportTestingQueueFakeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ public function testAssertPushedTimes()
176176
$this->fake->assertPushed(JobStub::class, 2);
177177
}
178178

179+
public function testAssertCount()
180+
{
181+
$this->fake->push(function () {
182+
// Do nothing
183+
});
184+
185+
$this->fake->push($this->job);
186+
$this->fake->push($this->job);
187+
188+
$this->fake->assertCount(3);
189+
}
190+
179191
public function testAssertNothingPushed()
180192
{
181193
$this->fake->assertNothingPushed();

0 commit comments

Comments
 (0)