From b008192a97c2d090972ae5fbb7df5bd49116106c Mon Sep 17 00:00:00 2001 From: Marco Hillger Date: Thu, 25 Aug 2016 17:56:40 +0200 Subject: [PATCH 1/3] WithoutEvents can fire ModelEvents to Test events fired ot of a Model event. --- .../Foundation/Testing/Concerns/MocksApplicationServices.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php b/src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php index c1fa076f2167..3a65ae9368da 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php +++ b/src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php @@ -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) { From 06d5a2dec685ca9e9f4e5155d084b080a03dbf8d Mon Sep 17 00:00:00 2001 From: Marco Hillger Date: Thu, 25 Aug 2016 18:56:19 +0200 Subject: [PATCH 2/3] added unit test --- .../Foundation/FoundationExpectsModelEventsTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Foundation/FoundationExpectsModelEventsTest.php b/tests/Foundation/FoundationExpectsModelEventsTest.php index 3411c1c0f355..64178bce191d 100644 --- a/tests/Foundation/FoundationExpectsModelEventsTest.php +++ b/tests/Foundation/FoundationExpectsModelEventsTest.php @@ -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); + + EloquentTestModel::create(['field' => 1]); + } + /** @test */ public function unfired_events_can_be_checked_for() { From 1c95d41de6af3a522541db62d5283db1150f7479 Mon Sep 17 00:00:00 2001 From: Marco Hillger Date: Thu, 25 Aug 2016 21:02:05 +0200 Subject: [PATCH 3/3] fixed ci --- tests/Foundation/FoundationExpectsModelEventsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Foundation/FoundationExpectsModelEventsTest.php b/tests/Foundation/FoundationExpectsModelEventsTest.php index 64178bce191d..e6959d074b4e 100644 --- a/tests/Foundation/FoundationExpectsModelEventsTest.php +++ b/tests/Foundation/FoundationExpectsModelEventsTest.php @@ -108,7 +108,7 @@ public function expects_model_events_can_take_a_string_as_the_event_name() /** @test */ public function expects_events_fires_on_model_events() { - EloquentTestModel::created(function() { + EloquentTestModel::created(function () { event(ExampleEvent::class); });