Skip to content

Unit testing with model event listeners is broken #5

@bgrawi

Description

@bgrawi

First see laravel/framework#1181 for context.

What winds up happening is that NONE of the event listeners for any of the traits ever get called after the first unit test is run. I currently have to use the hack provided by this comment laravel/framework#1181 (comment) in order to run more than one test using esensi/model.

I am inheriting my models directly from Esensi\Model\SoftModel, so the Esensi\Model\Model::bootTraits is only ever called on the first unit test. While yes, this is an issue with Laravel as a whole, the team seems to be recommending against assigning event watchers in a model's boot sequence regardless and have opted not to fix this issue. Instead, the generally accepted "non-hack" requires moving all event registration to app/start/global.php as per laravel/framework#1181 (comment)

This issue should be stated somewhere in your documentation. Also, the project should provide a way to quickly register all the required event listeners for models in app/start/global.php instead of in the boot process which has this severe defect. At the very least there should be some examples of manually registering the listeners.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions