orchestral/testbench

PHPStan showing connection errors in v8.23.0

Opened this issue · 4 comments

  • Testbench Version: 8.23
  • Laravel Version: 10.48.10
  • PHP Version: 8.1
  • Database Driver & Version: MySQL

Description:

Since core v8.24 has been installed, running PHPStan throws connection errors. If I lock my composer package to use core v8.23.10 these errors disappear (which requires v8.22.3 of Testbench)

Child process error (exit code 1):                                                                                                                                                                                                                  
     Internal error: Internal error: Database connection [xxx] not configured. while analysing file /tests/Models/UserTest.php

This package defines these connections and merges with a service provider. The tests run correctly.

$this->mergeConfigFrom(__DIR__ . '/../../config/connections.php', 'database.connections');

Steps To Reproduce:

Define database connections and merge them with a service provider
Create a test which uses the custom connection
Successfully run test on the custom connection
Run PHPStan

Testbench itself uses PHPStan 1.11 for code analysis and haven't seen this error.

The issue doesn't seem to be with PHPStan 1.11, as I use this on another project and running PHPStan works correctly. However, there seems to be a problem with finding the custom connections. I looked, but I can't see what changes were made between core v8.23.10 and v8.24 which triggers the errors.

There are only PHPStan syntax changes and using getenv('TESTBENCH_WORKING_PATH') instead of just using getcwd() to resolve the path. That shouldn't cause any changes to how Laravel is bootstrapped.

I am entirely unsure. Static Analysis shouldn't be running the code, so I don't know why this has become an issue, but with my investigation, it was introduced in the recent testbench-core update, as my test runners worked fine yesterday.