Skip to content

Commit

Permalink
[8.x] Add ::assertNothingDispatched() to Events::fake (#35835)
Browse files Browse the repository at this point in the history
* Add ::assertNothingDispatched() to events fake

* Update EventFake.php

* Update SupportTestingEventFakeTest.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
danilopolani and taylorotwell committed Jan 11, 2021
1 parent e8ba1d8 commit 374e956
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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

0 comments on commit 374e956

Please sign in to comment.