testbench icon indicating copy to clipboard operation
testbench copied to clipboard

PHPStan showing connection errors in v8.23.0

Open trovster opened this issue 1 year ago • 5 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

trovster avatar May 21 '24 13:05 trovster

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

crynobone avatar May 21 '24 14:05 crynobone

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.

trovster avatar May 21 '24 14:05 trovster

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.

crynobone avatar May 21 '24 15:05 crynobone

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.

trovster avatar May 21 '24 16:05 trovster

@trovster PHPStan it self does not run any code, but if you have installed the Larastan extension it will run the application container when ever it encounters a call to app(string), resolve(), app()->make(), App::make() or similar functions, it does this to try and figure out what object type is return with the given input.

I'm also having database connection issues after the changes made in that version of core and had to block the update in composer.

AJenbo avatar Aug 27 '24 07:08 AJenbo