orchestral / testbench

Laravel Testing Helper for Packages Development
https://packages.tools/testbench
MIT License
2.07k stars 137 forks source link

PHPStan showing connection errors in v8.23.0 #406

Open trovster opened 1 month ago

trovster commented 1 month ago

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

crynobone commented 1 month ago

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

trovster commented 1 month ago

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.

crynobone commented 1 month ago

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.

trovster commented 1 month ago

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.