Support the ongoing development of Laravel.io →
posted 9 years ago
Testing
Last updated 2 years ago.
0

If you event is an Eloquent event you may be affected by this bug. It happened to me a few days ago.

Assuming the event belongs to App\User model try executing this just before your assertions

App\User::flushEventListeners();
App\User::boot();

If that fixes your problem then you are affected by the bug. Fee free to implement a more elegant version of the workwaround.

Last updated 9 years ago.
0

Hi,

when you say eloquent event do you mean it is fired by hooking onto eloquents various stages? creation, update etc? then no it isnt. It gets fired in the controller.

oh man, i just reran the test (as i added another functionality) and didnt notice until now that my events expectation didnt give error anymore!!! I havent changed anything (i actually went in to add your code and realised i have ran the tests already)

weird...

0

I am currently having this same issue however the fix didn't help me solve the problem. I know my events are firing because i have put debugging code in them and can see that when running tests, yet it still says the event didn't fire and I am doing the following event

$this->expectsEvents('eloquent.saving: GroupMedia');

Here is some output, I am echoing the capitalized string from the actual event handler so i know the event is getting thrown as that is the only entry point to this method.

➜  l5_media_communities git:(laravel-5.2-testing) ✗ phpunit
PHPUnit 5.2.10 by Sebastian Bergmann and contributors.

.E                                                                  2 / 2 (100%)
YES THE EVENT HANDLER HAS BEEN EXECUTED!


Time: 1.21 seconds, Memory: 28.75Mb

There was 1 error:

1) UserEmailNotificationsTest::testMemberNewCommentEmailNotification
Exception: These expected events were not fired: [eloquent.saving: GroupMedia]
0

Sign in to participate in this thread!

Eventy

Your banner here too?

shez1983 shez1983 Joined 31 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.