Skip to content

DB::enableQueryLog not working when using DatabaseMigrations #3447

@btaskew

Description

@btaskew
  • Laravel-mongodb Version: 5.5.0
  • PHP Version: 8.4.4
  • Database Driver & Version: mongodb/mongodb 2.1.1

Description:

Using DB::enableQueryLog within a test that is using the DatabaseMigrations trait fails with an error Call to a member function addSubscriber() on null

The laravel-mongodb version of enableQueryLog is trying to access the connection property on the Connection class (see here). However since Laravel 12.22 the connection is disconnected after the database wipe, as part of the db migration within DatabaseMigrations, so the connection property is null. See Laravel PR 56368

Steps to reproduce

  1. Create unit test (PHPUnit or Pest) using DatabaseMigrations trait
  2. Add DB::enableQueryLog, either within the test or within the code
  3. Run the test

Expected behaviour

Query log should be enabled, and results should be visible from DB::getQueryLog

Actual behaviour

Test errors

Error: Call to a member function addSubscriber() on null
at vendor/mongodb/laravel-mongodb/src/Connection.php:186
at vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:489
at vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:363

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions