Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging in functional tests in case of connection failure #4006

Merged
merged 1 commit into from
May 12, 2020

Conversation

morozov
Copy link
Member

@morozov morozov commented May 12, 2020

Q A
Type regression
BC Break no

Summary

As of #3932, if a functional test fails to establish a DB connection on setup (e.g. due to invalid configuration), it fails like this:

$ phpunit -c mysqli.phpunit.xml tests/Functional/ConnectionTest.php --stop-on-error
PHPUnit 9.1.1 by Sebastian Bergmann and contributors.

E

Time: 319 ms, Memory: 6.00 MB

There was 1 error:

1) Doctrine\DBAL\Tests\Functional\ConnectionTest::testGetWrappedConnection
Trying to get property 'queries' of non-object

/home/morozov/Projects/dbal/tests/FunctionalTestCase.php:72

The expected behavior is:

$ phpunit -c mysqli.phpunit.xml tests/Functional/ConnectionTest.php --stop-on-error
PHPUnit 9.1.1 by Sebastian Bergmann and contributors.

E

Time: 310 ms, Memory: 6.00 MB

There was 1 error:

1) Doctrine\DBAL\Tests\Functional\ConnectionTest::testGetWrappedConnection
Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: php_network_getaddresses: getaddrinfo failed: Name or service not known

The reason is that we no longer check if (isset($this->sqlLoggerStack->queries) because $sqlLoggerStack is of type DebugStack and it's assumed that the $queries property is always set. Although, in the case of a connection failure, the logger is not initialized.

The solution is to initialize the logger before trying to connect.

@morozov morozov added this to the 3.0.0 milestone May 12, 2020
@morozov morozov requested a review from greg0ire May 12, 2020 01:51
@morozov morozov merged commit 1510b7c into doctrine:3.0.x May 12, 2020
@morozov morozov deleted the functional-connect-failure branch May 12, 2020 06:09
@morozov morozov self-assigned this May 12, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants