Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add ::assertNothingDispatched() to events fake
  • Loading branch information
danilopolani committed Jan 9, 2021
commit 0cf141ca6a3c282dc20ae82cf4fe33b051cfde15
15 changes: 15 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/EventFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public function assertNotDispatched($event, $callback = null)
);
}

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

PHPUnit::assertSame(
0, $count,
"Unexpected {$count} 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
Original file line number Diff line number Diff line change
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('Unexpected 2 events were dispatched.'));
}
}
}

class EventStub
Expand Down