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

[8.x] Add ::assertNothingDispatched() to Events::fake #35835

Merged
merged 3 commits into from Jan 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/EventFake.php
Expand Up @@ -106,6 +106,21 @@ public function assertNotDispatched($event, $callback = null)
);
}

/**
* Assert that no events were dispatched.
*
* @return void
*/
public function assertNothingDispatched()
{
$count = count(Arr::flatten($this->events));

PHPUnit::assertSame(
0, $count,
"{$count} unexpected events were dispatched."
);
}

/**
* Get all of the events matching a truth-test callback.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Support/SupportTestingEventFakeTest.php
Expand Up @@ -118,6 +118,21 @@ function ($event, $payload) {
$fake->assertDispatched('Bar');
$fake->assertNotDispatched('Baz');
}

public function testAssertNothingDispatched()
{
$this->fake->assertNothingDispatched();

$this->fake->dispatch(EventStub::class);
$this->fake->dispatch(EventStub::class);

try {
$this->fake->assertNothingDispatched();
$this->fail();
} catch (ExpectationFailedException $e) {
$this->assertThat($e, new ExceptionMessage('2 unexpected events were dispatched.'));
}
}
}

class EventStub
Expand Down