From 78d1167544a363b096c16005ff2c4b1d1f5c40da Mon Sep 17 00:00:00 2001 From: Jason McCreary Date: Mon, 25 Nov 2024 12:32:20 -0500 Subject: [PATCH 1/2] Assert nothing was placed on bus --- .../Support/Testing/Fakes/BusFake.php | 11 +++++ tests/Support/SupportTestingBusFakeTest.php | 41 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/Illuminate/Support/Testing/Fakes/BusFake.php b/src/Illuminate/Support/Testing/Fakes/BusFake.php index 89250efef79..83850f2b4ee 100644 --- a/src/Illuminate/Support/Testing/Fakes/BusFake.php +++ b/src/Illuminate/Support/Testing/Fakes/BusFake.php @@ -504,6 +504,17 @@ public function assertNothingBatched() PHPUnit::assertEmpty($this->batches, "The following batched jobs were dispatched unexpectedly:\n\n- $jobNames\n"); } + /** + * Assert that no jobs were dispatched, chained, or batched. + * + * @return void + */ + public function assertNothingPlaced() + { + $this->assertNothingDispatched(); + $this->assertNothingBatched(); + } + /** * Get all of the jobs matching a truth-test callback. * diff --git a/tests/Support/SupportTestingBusFakeTest.php b/tests/Support/SupportTestingBusFakeTest.php index c6705137af2..2e6d836974b 100644 --- a/tests/Support/SupportTestingBusFakeTest.php +++ b/tests/Support/SupportTestingBusFakeTest.php @@ -661,6 +661,47 @@ public function testAssertNothingBatched() } } + public function testAssertEmptyPasses() + { + $this->fake->assertNothingPlaced(); + } + + public function testAssertEmptyFailedWhenJobBatched() + { + $this->fake->batch([new BusJobStub])->dispatch(); + + $this->expectException(ExpectationFailedException::class); + + $this->fake->assertNothingPlaced(); + } + + public function testAssertEmptyFailedWhenJobDispatched() + { + $this->fake->dispatch(new BusJobStub); + + $this->expectException(ExpectationFailedException::class); + + $this->fake->assertNothingPlaced(); + } + + public function testAssertEmptyFailedWhenJobChained() + { + $this->fake->chain([new ChainedJobStub])->dispatch(); + + $this->expectException(ExpectationFailedException::class); + + $this->fake->assertNothingPlaced(); + } + + public function testAssertEmptyFailedWhenJobDispatchedNow() + { + $this->fake->dispatchNow(new BusJobStub); + + $this->expectException(ExpectationFailedException::class); + + $this->fake->assertNothingPlaced(); + } + public function testFindBatch() { $this->assertNull($this->fake->findBatch('non-existent-batch')); From 23bc6552ae3fd39e2b754f6bf9c4ac125fec0150 Mon Sep 17 00:00:00 2001 From: Jason McCreary Date: Mon, 25 Nov 2024 12:32:50 -0500 Subject: [PATCH 2/2] Alias for asserting nothing was chained --- src/Illuminate/Support/Testing/Fakes/BusFake.php | 10 ++++++++++ tests/Support/SupportTestingBusFakeTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Support/Testing/Fakes/BusFake.php b/src/Illuminate/Support/Testing/Fakes/BusFake.php index 83850f2b4ee..73b05ff6e56 100644 --- a/src/Illuminate/Support/Testing/Fakes/BusFake.php +++ b/src/Illuminate/Support/Testing/Fakes/BusFake.php @@ -361,6 +361,16 @@ public function assertChained(array $expectedChain) $this->assertDispatchedWithChainOfObjects($command, $expectedChain, $callback); } + /** + * Assert no chained jobs was dispatched. + * + * @return void + */ + public function assertNothingChained() + { + $this->assertNothingDispatched(); + } + /** * Reset the chain properties to their default values on the job. * diff --git a/tests/Support/SupportTestingBusFakeTest.php b/tests/Support/SupportTestingBusFakeTest.php index 2e6d836974b..68b471c780d 100644 --- a/tests/Support/SupportTestingBusFakeTest.php +++ b/tests/Support/SupportTestingBusFakeTest.php @@ -548,6 +548,20 @@ public function testAssertChained() Container::setInstance(null); } + public function testAssertNothingChained() + { + $this->fake->assertNothingChained(); + } + + public function testAssertNothingChainedFails() + { + $this->fake->chain([new ChainedJobStub])->dispatch(); + + $this->expectException(ExpectationFailedException::class); + + $this->fake->assertNothingChained(); + } + public function testAssertDispatchedWithIgnoreClass() { $dispatcher = m::mock(QueueingDispatcher::class);