During a Codeception test using the Laravel module, the application is loaded every time refreshing the dynamic components of the system. But certain static fields aren't reset between test runs, so it breaks the system.
Specifically, a new instance of Dispatcher
is set on Eloquent models, but the Model's booted
flags are not reset.
After the first test run, no models in the system will have listeners attached.
So to solve this issue, I made a custom test hook that resets the model booted
flags after each test run.
Paste ModelResetExtension.php
into your _support
directory (located in your test directory.
Then add an entry in codeception.yml
to enable this extension.
extensions:
enabled:
- ModelResetExtension