Skip to content

[2.x] ShouldHandleEventsAfterCommit/ShouldDispatchAfterCommit listeners should be executed after nested transaction is commited during tests #5022

Description

@novacuum

Current Behavior

The tests implemented in #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 #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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions