- 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
- Create unit test (PHPUnit or Pest) using
DatabaseMigrations trait
- Add
DB::enableQueryLog, either within the test or within the code
- 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
Description:
Using
DB::enableQueryLogwithin a test that is using theDatabaseMigrationstrait fails with an errorCall to a member function addSubscriber() on nullThe laravel-mongodb version of
enableQueryLogis trying to access theconnectionproperty on theConnectionclass (see here). However since Laravel 12.22 the connection is disconnected after the database wipe, as part of the db migration withinDatabaseMigrations, so theconnectionproperty is null. See Laravel PR 56368Steps to reproduce
DatabaseMigrationstraitDB::enableQueryLog, either within the test or within the codeExpected behaviour
Query log should be enabled, and results should be visible from
DB::getQueryLogActual behaviour
Test errors