Laravel Version
10.43.0
PHP Version
8.2.x
Database Driver & Version
No response
Description
Hey.
DB::afterCommit() and subsequently "after commit" jobs (and notifications, listeners, events etc) are incorrectly immediately executed when inside of a transaction in a PHPUnit test that uses DatabaseTransactions if the test has committed a transaction before:
class SomeTest extends TestCase {
use DatabaseTransactions;
public function testSomething(): void
{
DB::transaction(function () {});
DB::transaction(function () {
// This line should only execute after this closure
DB::afterCommit(fn () => dd(123));
// This line should execute first, before the line above
dd(456);
});
}
}
which prints 123.
Steps To Reproduce
- Copy the test case above into a Laravel ^10.34 application and run it
Actual result is 123
Expected result is 456