When a connection has parameters defined dynamically at runtime, the same wrapped connection is used because the cache key is only based on the connection's name, leading to using a connection that does not honor the parameters.
Always using a cache key based on all parameters (including connection's name) prevents this.
I faced this issue while running a PHPUnit test suite in which the database name is defined via an environment variable and changes depending on the tests. When running the entire suite, some tests failed because they connected to the wrong database (the one used for the first test that created a connection) while each test passed when run individually.
When a connection has parameters defined dynamically at runtime, the same wrapped connection is used because the cache key is only based on the connection's name, leading to using a connection that does not honor the parameters.
Always using a cache key based on all parameters (including connection's name) prevents this.
I faced this issue while running a PHPUnit test suite in which the database name is defined via an environment variable and changes depending on the tests. When running the entire suite, some tests failed because they connected to the wrong database (the one used for the first test that created a connection) while each test passed when run individually.