[2.x] ShouldHandleEventsAfterCommit/ShouldDispatchAfterCommit listeners should be executed after nested transaction is commited during tests
Author: novacuumCreated Sep 1, 2026Updated Sep 1, 2026
Labelstype/bug
Current Behavior
The tests implemented in https://github.com/flarum/framework/pull/4833 are missing to test the behaviour when the application code creates a transaction in it self (results in a nested transaction).
The fix in https://github.com/flarum/framework/pull/4833 leads to that an event marked with ShouldDispatchAfterCommit is dispatched to early during tests.
Steps to Reproduce
Extend the AfterCommitListenerTest test case with following code and resolve deps:
#[Test]
public function after_commit_event_is_dispatched_after_a_transaction(): void
{
$this->extend(
(new Extend\Event())->listen(AfterCommitDispatchableEvent::class, function () use (&$ran) {
$ran = true;
})
);
$this->connection()->beginTransaction();
$this->app()->getContainer()->make(Dispatcher::class)->dispatch(new AfterCommitDispatchableEvent());
$this->assertFalse(
$ran,
'A ShouldDispatchAfterCommit event should not be dispatched during a nested transaction in a test.'
);
$this->connection()->commit();
$this->assertTrue(
$ran,
'A ShouldDispatchAfterCommit event should be dispatched during an integration test.'
);
}
private function connection(): ConnectionInterface
{
return $this->app()->getContainer()->make(ConnectionInterface::class);
}Expected Behavior
test should run
Screenshots
No response
Environment
- Flarum version: 2.0.0-rc.8
- Website URL: http://example.com
- Webserver: [e.g. apache, nginx]
- Hosting environment: [e.g. shared, vps]
- PHP version: x.y.z
- Database: [e.g. MySQL 8.4.11, MariaDB 10.11.2, PostgreSQL 16.1, SQLite 3.45]
- Browser: [e.g. chrome 67, safari 11]
Output of php flarum info
Output of "php flarum info", run this in terminal in your Flarum directory.Possible Solution
No response
Additional Context
No response
Source: flarum/framework