Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus assertempty #53664

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
jasonmccreary marked this conversation as resolved.
Show resolved Hide resolved
{
$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