Closed
Description
Laravel Version
10.23.1
PHP Version
8.2.10
Database Driver & Version
8.0.33
Description
In tests, model observer created
does not run if all condition applies:
- Test uses mysql DB connection.
- Test uses
RefreshDatabase
trait. - Using
createOrFirst()
orfirstOrCreate()
method and the method is insideDB::transaction()
.
This issue started to appear in laravel/framework 10.21. I think it was introduced in #48144
Steps To Reproduce
- Clone TestDBTransaction sample project.
- Make sure to update mysql database connection in your .env file.
- Run
vendor/bin/phpunit
. Test should pass but it fails. - Try to comment the lines under Failing Test (line 27 and 30) section and uncomment a line from the Passing Tests (line 35 or 38) in
NoteObserverTest
. Test now passes.