1919use Doctrine \ORM \Query ;
2020use Doctrine \ORM \Tools \SchemaTool ;
2121use LogicException ;
22- use mysqli ;
2322use PDO ;
2423use PHPStan \Php \PhpVersion ;
2524use PHPStan \Platform \Entity \PlatformEntity ;
4847use PHPUnit \Framework \Constraint \IsEqual ;
4948use PHPUnit \Framework \Constraint \IsIdentical ;
5049use Platform \TypedExpressionBooleanPiFunction ;
51- use SQLite3 ;
5250use Throwable ;
5351use function floor ;
54- use function function_exists ;
55- use function get_debug_type ;
5652use function getenv ;
57- use function gettype ;
5853use function in_array ;
59- use function is_a ;
60- use function is_resource ;
61- use function method_exists ;
6254use function reset ;
6355use function sprintf ;
6456use function var_export ;
@@ -3462,14 +3454,10 @@ public static function provideCases(): iterable
34623454 },
34633455 ];
34643456
3465- // TODO postgres ->setUseBooleanTrueFalseStrings()
34663457 // TODO string TypedExpression does not cast to string
3467- // TODO sqlsrv uses native DateTime
34683458 // TODO would col_numeric_string differ from col_string results ?
34693459 // TODO dbal/orm versions
3470- // TODO unknown driver to return mixed everywhere
34713460 // TODO double check all inferred unions
3472- // TODO check else branches & default behaviour (other drivers)
34733461 }
34743462
34753463 /**
@@ -3488,10 +3476,14 @@ private function performDriverTest(
34883476 callable $ assertStringified
34893477 ): void
34903478 {
3491- $ connectionParams = ['driver ' => $ driver ] + $ this ->getConnectionParamsForDriver ($ driver );
3479+ $ connectionParams = [
3480+ 'driver ' => $ driver ,
3481+ 'driverOptions ' => self ::CONNECTION_CONFIGS [$ configName ],
3482+ ] + $ this ->getConnectionParamsForDriver ($ driver );
3483+
34923484 $ dql = sprintf ($ dqlTemplate , PlatformEntity::class);
34933485
3494- $ connection = $ this ->createConnection ($ connectionParams, self :: CONNECTION_CONFIGS [ $ configName ] );
3486+ $ connection = $ this ->createConnection ($ connectionParams );
34953487 $ query = $ this ->getQuery ($ connection , $ dql , $ data );
34963488 $ sql = $ query ->getSQL ();
34973489
@@ -3538,11 +3530,9 @@ private function performDriverTest(
35383530
35393531 /**
35403532 * @param array<string, mixed> $connectionParams
3541- * @param array<mixed> $connectionAttributes
35423533 */
35433534 private function createConnection (
3544- array $ connectionParams ,
3545- array $ connectionAttributes
3535+ array $ connectionParams
35463536 ): Connection
35473537 {
35483538 $ connection = DriverManager::getConnection ($ connectionParams );
@@ -3554,9 +3544,6 @@ private function createConnection(
35543544 $ connection ->executeQuery ('USE foo ' );
35553545 }
35563546
3557- $ nativeConnection = $ this ->getNativeConnection ($ connection );
3558- $ this ->setupAttributes ($ nativeConnection , $ connectionAttributes );
3559-
35603547 return $ connection ;
35613548 }
35623549
@@ -3976,70 +3963,6 @@ private static function stringifyType(Type $type): Type
39763963 });
39773964 }
39783965
3979- /**
3980- * @param mixed $nativeConnection
3981- * @param array<mixed> $attributes
3982- */
3983- private function setupAttributes ($ nativeConnection , array $ attributes ): void
3984- {
3985- if ($ nativeConnection instanceof PDO ) {
3986- foreach ($ attributes as $ attribute => $ value ) {
3987- $ set = $ nativeConnection ->setAttribute ($ attribute , $ value );
3988- if (!$ set ) {
3989- throw new LogicException (sprintf ('Failed to set attribute %s to %s ' , $ attribute , $ value ));
3990- }
3991- }
3992-
3993- } elseif ($ nativeConnection instanceof mysqli) {
3994- foreach ($ attributes as $ attribute => $ value ) {
3995- $ set = $ nativeConnection ->options ($ attribute , $ value );
3996- if (!$ set ) {
3997- throw new LogicException (sprintf ('Failed to set attribute %s to %s ' , $ attribute , $ value ));
3998- }
3999- }
4000-
4001- } elseif (is_a ($ nativeConnection , 'PgSql\Connection ' , true )) {
4002- if ($ attributes !== []) {
4003- throw new LogicException ('Cannot set attributes for PgSql\Connection driver ' );
4004- }
4005-
4006- } elseif ($ nativeConnection instanceof SQLite3) {
4007- if ($ attributes !== []) {
4008- throw new LogicException ('Cannot set attributes for ' . SQLite3::class . ' driver ' );
4009- }
4010-
4011- } elseif (is_resource ($ nativeConnection )) { // e.g. `resource (pgsql link)` on PHP < 8.1 with pgsql driver
4012- if ($ attributes !== []) {
4013- throw new LogicException ('Cannot set attributes for this resource ' );
4014- }
4015-
4016- } else {
4017- throw new LogicException ('Unexpected connection: ' . (function_exists ('get_debug_type ' ) ? get_debug_type ($ nativeConnection ) : gettype ($ nativeConnection )));
4018- }
4019- }
4020-
4021- /**
4022- * @return mixed
4023- */
4024- private function getNativeConnection (Connection $ connection )
4025- {
4026- if (method_exists ($ connection , 'getNativeConnection ' )) {
4027- return $ connection ->getNativeConnection ();
4028- }
4029-
4030- if (method_exists ($ connection , 'getWrappedConnection ' )) {
4031- if ($ connection ->getWrappedConnection () instanceof PDO ) {
4032- return $ connection ->getWrappedConnection ();
4033- }
4034-
4035- if (method_exists ($ connection ->getWrappedConnection (), 'getWrappedResourceHandle ' )) {
4036- return $ connection ->getWrappedConnection ()->getWrappedResourceHandle ();
4037- }
4038- }
4039-
4040- throw new LogicException ('Unable to get native connection ' );
4041- }
4042-
40433966 private static function defaultStringification (Driver $ driver , int $ php , string $ configName ): bool
40443967 {
40453968 if ($ configName === self ::CONFIG_DEFAULT ) {
0 commit comments