Skip to content

Commit

Permalink
[10.x] Add assertCount test helper (#49609)
Browse files Browse the repository at this point in the history
* Add assertCount method

* apply StyleCI

* Update QueueFake.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
xurshudyan and taylorotwell authored Jan 7, 2024
1 parent 0807344 commit d476191
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/QueueFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ public function assertNotPushed($job, $callback = null)
);
}

/**
* Assert the total count of jobs that were pushed.
*
* @param int $expectedCount
* @return void
*/
public function assertCount($expectedCount)
{
$actualCount = collect($this->jobs)->flatten(1)->count();

PHPUnit::assertSame(
$expectedCount, $actualCount,
"Expected {$expectedCount} jobs to be pushed, but found {$actualCount} instead."
);
}

/**
* Assert that no jobs were pushed.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Support/SupportTestingQueueFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ public function testAssertPushedTimes()
$this->fake->assertPushed(JobStub::class, 2);
}

public function testAssertCount()
{
$this->fake->push(function () {
// Do nothing
});

$this->fake->push($this->job);
$this->fake->push($this->job);

$this->fake->assertCount(3);
}

public function testAssertNothingPushed()
{
$this->fake->assertNothingPushed();
Expand Down

0 comments on commit d476191

Please sign in to comment.