Skip to content

Commit

Permalink
Bus assertempty (#53664)
Browse files Browse the repository at this point in the history
* Assert nothing was placed on bus

* Alias for asserting nothing was chained
  • Loading branch information
jasonmccreary authored Nov 25, 2024
1 parent 77f104d commit e94a5cb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/BusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -504,6 +514,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.
*
Expand Down
55 changes: 55 additions & 0 deletions tests/Support/SupportTestingBusFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -661,6 +675,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'));
Expand Down

0 comments on commit e94a5cb

Please sign in to comment.