-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Tests setUp() resets Model Events #4975
Comments
I think this might be related to #1181 ? |
I see, it seems to be related indeed. Seems to be a recurring issue because a lot of people is affected. I will try to investigate a little more when I can, until then I guess those hacks they mention should work. Thanks for the heads up. |
EspadaV8
pushed a commit
to EspadaV8/eloquent-versioned
that referenced
this issue
Jun 9, 2015
There are a number of issues related to Laravel not firing model events when using PHPUnit laravel/framework#1181 laravel/framework#4975 This package seems to help with that https://github.com/orchestral/testbench
EspadaV8
pushed a commit
to EspadaV8/eloquent-versioned
that referenced
this issue
Jun 9, 2015
There are a number of issues related to Laravel not firing model events when using PHPUnit laravel/framework#1181 laravel/framework#4975 This package seems to help with that https://github.com/orchestral/testbench
EspadaV8
pushed a commit
to EspadaV8/eloquent-versioned
that referenced
this issue
Jun 9, 2015
There are a number of issues related to Laravel not firing model events when using PHPUnit laravel/framework#1181 laravel/framework#4975 This package seems to help with that https://github.com/orchestral/testbench
EspadaV8
pushed a commit
to EspadaV8/eloquent-versioned
that referenced
this issue
Jun 10, 2015
There are a number of issues related to Laravel not firing model events when using PHPUnit laravel/framework#1181 laravel/framework#4975 This package seems to help with that https://github.com/orchestral/testbench
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I've had some issues with my tests after adding some new logic with Model Events. After some investigations, I have found the issue is that whenever the method setUp() is called for the second time in a test, the Model Event listeners are cleared away from models. I don't know the exact reason, but it happens because the method refreshApplication() is called every time which causes the event dispatcher to be resetted. So the execution trace is the following:
0: I don't know what's called before
1: Illuminate\Foundation\Testing\TestCase->refreshApplication()
2: Illuminate\Foundation\Application->boot()
3: Illuminate\Database\DatabaseServiceProvider->boot()
4: Illuminate\Database\Eloquent\Model::setEventDispatcher::setEventDispatcher() // Here event dispatcher is resetted
In case this is not comprehensible enough (probably), here I have a reproducable scenario of what I did to find the bug in a clean laravel installation:
Given the following model:
And the following test class:
When phpunit is executed, the second test will fail. I can provide more details if needed, but I think this is enough already. If this is not solved easily, I will try to help doing some more code inspection.
Thanks.
The text was updated successfully, but these errors were encountered: