Skip to content

afterCommit() callbacks do not fire when RefreshDatabase handles multiple $connectionsToTransact #48472

Closed
@mpyw

Description

@mpyw

Laravel Version

10.24.0

PHP Version

irrelevant

Database Driver & Version

irrelevant

Description

When multiple connections are specified in $connectionsToTransact (default value: [null]), any callback functions specified in DB::afterCommit() will not be executed.

Steps To Reproduce

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    protected $connectionsToTransact = [null, 'sqlite'];

    use RefreshDatabase;

    public function testExample(): void
    {
        $executed = false;

        DB::transaction(function () use (&$executed) {
            DB::afterCommit(function () use (&$executed) {
                $executed = true;
            });
        });

        $this->assertTrue($executed);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions