Closed
Description
- Laravel Version: v8.21.0
- PHP Version: 7.4.11
- Database Driver & Version: psql (PostgreSQL) 12.4 (Ubuntu 12.4-1.pgdg20.04+1) - It doesn't depend on DB driver.
Description:
DB::afterCommit
callbacks aren't run when RefreshDatabase
trait is used because ManagesTransactions
trait only commits when all transactions are executed, but RefreshDatabase
uses a transaction. Then the callbacks aren't called.
Steps To Reproduce:
I've created a reproduction repo: https://github.com/mariomka/laravel-after-commit-repro
There are two tests, one with RefreshDatabase
(it fails) and one without RefreshDatabase
(it passes): https://github.com/mariomka/laravel-after-commit-repro/tree/master/tests
Both tests run the same "action": https://github.com/mariomka/laravel-after-commit-repro/blob/master/app/AfterCommitAction.php
Step by step reproduction:
git clone git@github.com:mariomka/laravel-after-commit-repro.git
cd laravel-after-commit-repro
cp .env.example .env
composer install
php vendor/bin/homestead make
# Enable postgresql in Homestead.yaml
vagrant up
vagrant ssh
cd code
php vendor/bin/phpunit