From 6f7b55518568bf151276c565b1a04ce84aab14b2 Mon Sep 17 00:00:00 2001 From: Volodya Kurshudyan Date: Sun, 7 Jan 2024 16:05:38 +0400 Subject: [PATCH 1/3] Add assertCount method --- .../Support/Testing/Fakes/QueueFake.php | 16 ++++++++++++++++ tests/Support/SupportTestingQueueFakeTest.php | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Illuminate/Support/Testing/Fakes/QueueFake.php b/src/Illuminate/Support/Testing/Fakes/QueueFake.php index 4117d5619754..aa1fdb879c6f 100644 --- a/src/Illuminate/Support/Testing/Fakes/QueueFake.php +++ b/src/Illuminate/Support/Testing/Fakes/QueueFake.php @@ -120,6 +120,22 @@ protected function assertPushedTimes($job, $times = 1) ); } + /** + * Assert the total count of jobs that were pushed. + * + * @param int $expectedCount + * @return void + */ + public function assertCount($expectedCount) + { + $actualCount = $this->size(); + + PHPUnit::assertSame( + $expectedCount, $actualCount, + "Expected {$expectedCount} jobs to be pushed, but found {$actualCount} instead." + ); + } + /** * Assert if a job was pushed based on a truth-test callback. * diff --git a/tests/Support/SupportTestingQueueFakeTest.php b/tests/Support/SupportTestingQueueFakeTest.php index e10f83ff1f8d..9e99ef01aa7f 100644 --- a/tests/Support/SupportTestingQueueFakeTest.php +++ b/tests/Support/SupportTestingQueueFakeTest.php @@ -176,6 +176,18 @@ public function testAssertPushedTimes() $this->fake->assertPushed(JobStub::class, 2); } + public function testAssertCount() + { + $this->fake->push(function () { + + }); + + $this->fake->push($this->job); + $this->fake->push($this->job); + + $this->fake->assertCount(3); + } + public function testAssertNothingPushed() { $this->fake->assertNothingPushed(); From 4997ef42cf12f0943b8c180738ef7f090b310b1e Mon Sep 17 00:00:00 2001 From: Volodya Kurshudyan Date: Sun, 7 Jan 2024 16:10:09 +0400 Subject: [PATCH 2/3] apply StyleCI --- tests/Support/SupportTestingQueueFakeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Support/SupportTestingQueueFakeTest.php b/tests/Support/SupportTestingQueueFakeTest.php index 9e99ef01aa7f..dd632426d543 100644 --- a/tests/Support/SupportTestingQueueFakeTest.php +++ b/tests/Support/SupportTestingQueueFakeTest.php @@ -179,7 +179,7 @@ public function testAssertPushedTimes() public function testAssertCount() { $this->fake->push(function () { - + // Do nothing }); $this->fake->push($this->job); From 1b2d21a00bd1dce3d88542ed85640a8e70dc9541 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Jan 2024 09:19:35 -0600 Subject: [PATCH 3/3] Update QueueFake.php --- .../Support/Testing/Fakes/QueueFake.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Illuminate/Support/Testing/Fakes/QueueFake.php b/src/Illuminate/Support/Testing/Fakes/QueueFake.php index aa1fdb879c6f..d0da55de1b41 100644 --- a/src/Illuminate/Support/Testing/Fakes/QueueFake.php +++ b/src/Illuminate/Support/Testing/Fakes/QueueFake.php @@ -120,22 +120,6 @@ protected function assertPushedTimes($job, $times = 1) ); } - /** - * Assert the total count of jobs that were pushed. - * - * @param int $expectedCount - * @return void - */ - public function assertCount($expectedCount) - { - $actualCount = $this->size(); - - PHPUnit::assertSame( - $expectedCount, $actualCount, - "Expected {$expectedCount} jobs to be pushed, but found {$actualCount} instead." - ); - } - /** * Assert if a job was pushed based on a truth-test callback. * @@ -294,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. *