Skip to content

Fix merging driver options in the pdo_sqlsrv driver test #6871

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

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

morozov
Copy link
Member

@morozov morozov commented Mar 23, 2025

This issue affects only the test suite and only if the pdo_sqlsrv connection is configured with additional DSN parameters, for instance:

<var name="db_driver_option_TrustServerCertificate" value="1" />

In this case, the testDriverOptions() test will fail with the following error:

phpunit -c phpunit-pdo-sqlsrv.xml \
  --filter testDriverOptions \
  tests/Functional/Driver/PDO/SQLSrv/DriverTest.php

There was 1 error:

1) Doctrine\DBAL\Tests\Functional\Driver\PDO\SQLSrv\DriverTest::testDriverOptions
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[IMSSP]: An unsupported attribute was designated on the PDO object.

src/Driver/PDO/Exception.php:24
src/Driver/PDO/SQLSrv/Driver.php:65
tests/Functional/Driver/PDO/SQLSrv/DriverTest.php:50
tests/Functional/Driver/PDO/SQLSrv/DriverTest.php:68

The reason is that the pdo_sqlsrv DBAL driver accepts both the DSN and PDO parameters in the driverOptions connection parameter:

if (is_int($option)) {
$driverOptions[$option] = $value;
} else {
$dsnOptions[$option] = $value;
}

Prior to the fix, the code would merge the configuration provided by PHPUnit with the configuration provided by the test using array_merge() and lose the key representing the PDO attribute:

$dsnOptions = ['TrustServerCertificate' => '1'];
$pdoOptions = [8 => 1];

var_dump(array_merge($dsnOptions, $pdoOptions));

// array(2) {
//   ["TrustServerCertificate"]=>
//   string(1) "1"
//   [0]=>
//   int(1)
// }

array_replace() preserves numeric keys in the case if both string string keys designated for the DSN and numeric keys designated for PDO are present.

array_replace() preserves numeric keys in the case if both string string
keys designated for the DSN and numeric keys designated for PDO are
present.
@morozov morozov added this to the 4.2.4 milestone Mar 23, 2025
@morozov morozov marked this pull request as ready for review March 23, 2025 23:13
@morozov morozov requested a review from greg0ire March 23, 2025 23:13
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@morozov morozov merged commit 83cf7e1 into doctrine:4.2.x Mar 24, 2025
66 checks passed
@morozov morozov deleted the fix-pdo-sql-driver-test branch March 24, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants