19
19
use Doctrine \ORM \Query ;
20
20
use Doctrine \ORM \Tools \SchemaTool ;
21
21
use LogicException ;
22
- use mysqli ;
23
22
use PDO ;
24
23
use PHPStan \Php \PhpVersion ;
25
24
use PHPStan \Platform \Entity \PlatformEntity ;
48
47
use PHPUnit \Framework \Constraint \IsEqual ;
49
48
use PHPUnit \Framework \Constraint \IsIdentical ;
50
49
use Platform \TypedExpressionBooleanPiFunction ;
51
- use SQLite3 ;
52
50
use Throwable ;
53
51
use function floor ;
54
- use function function_exists ;
55
- use function get_debug_type ;
56
52
use function getenv ;
57
- use function gettype ;
58
53
use function in_array ;
59
- use function is_a ;
60
- use function is_resource ;
61
- use function method_exists ;
62
54
use function reset ;
63
55
use function sprintf ;
64
56
use function var_export ;
@@ -3462,14 +3454,10 @@ public static function provideCases(): iterable
3462
3454
},
3463
3455
];
3464
3456
3465
- // TODO postgres ->setUseBooleanTrueFalseStrings()
3466
3457
// TODO string TypedExpression does not cast to string
3467
- // TODO sqlsrv uses native DateTime
3468
3458
// TODO would col_numeric_string differ from col_string results ?
3469
3459
// TODO dbal/orm versions
3470
- // TODO unknown driver to return mixed everywhere
3471
3460
// TODO double check all inferred unions
3472
- // TODO check else branches & default behaviour (other drivers)
3473
3461
}
3474
3462
3475
3463
/**
@@ -3488,10 +3476,14 @@ private function performDriverTest(
3488
3476
callable $ assertStringified
3489
3477
): void
3490
3478
{
3491
- $ connectionParams = ['driver ' => $ driver ] + $ this ->getConnectionParamsForDriver ($ driver );
3479
+ $ connectionParams = [
3480
+ 'driver ' => $ driver ,
3481
+ 'driverOptions ' => self ::CONNECTION_CONFIGS [$ configName ],
3482
+ ] + $ this ->getConnectionParamsForDriver ($ driver );
3483
+
3492
3484
$ dql = sprintf ($ dqlTemplate , PlatformEntity::class);
3493
3485
3494
- $ connection = $ this ->createConnection ($ connectionParams, self :: CONNECTION_CONFIGS [ $ configName ] );
3486
+ $ connection = $ this ->createConnection ($ connectionParams );
3495
3487
$ query = $ this ->getQuery ($ connection , $ dql , $ data );
3496
3488
$ sql = $ query ->getSQL ();
3497
3489
@@ -3538,11 +3530,9 @@ private function performDriverTest(
3538
3530
3539
3531
/**
3540
3532
* @param array<string, mixed> $connectionParams
3541
- * @param array<mixed> $connectionAttributes
3542
3533
*/
3543
3534
private function createConnection (
3544
- array $ connectionParams ,
3545
- array $ connectionAttributes
3535
+ array $ connectionParams
3546
3536
): Connection
3547
3537
{
3548
3538
$ connection = DriverManager::getConnection ($ connectionParams );
@@ -3554,9 +3544,6 @@ private function createConnection(
3554
3544
$ connection ->executeQuery ('USE foo ' );
3555
3545
}
3556
3546
3557
- $ nativeConnection = $ this ->getNativeConnection ($ connection );
3558
- $ this ->setupAttributes ($ nativeConnection , $ connectionAttributes );
3559
-
3560
3547
return $ connection ;
3561
3548
}
3562
3549
@@ -3976,70 +3963,6 @@ private static function stringifyType(Type $type): Type
3976
3963
});
3977
3964
}
3978
3965
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
-
4043
3966
private static function defaultStringification (Driver $ driver , int $ php , string $ configName ): bool
4044
3967
{
4045
3968
if ($ configName === self ::CONFIG_DEFAULT ) {
0 commit comments