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

[5.3] expectsEvents fired from ModelEvents #15052

Merged
merged 3 commits into from
Aug 26, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public function doesntExpectEvents($events)
*/
protected function withoutEvents()
{
$this->withoutModelEvents();

$mock = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');

$mock->shouldReceive('fire')->andReturnUsing(function ($called) {
Expand Down
12 changes: 12 additions & 0 deletions tests/Foundation/FoundationExpectsModelEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ public function expects_model_events_can_take_a_string_as_the_event_name()
EloquentTestModel::create(['field' => 1]);
}

/** @test */
public function expects_events_fires_on_model_events()
{
EloquentTestModel::created(function () {
event(ExampleEvent::class);
});

$this->expectsEvents(ExampleEvent::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you put that code here before you register that created callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes no difference because the event will be mocked before the creation and override the ModelEvents.


EloquentTestModel::create(['field' => 1]);
}

/** @test */
public function unfired_events_can_be_checked_for()
{
Expand Down