@@ -2763,23 +2763,26 @@ private function performDriverTest(
2763
2763
$ connectionParams = ['driver ' => $ driver ] + $ this ->getConnectionParamsForDriver ($ driver );
2764
2764
$ dql = sprintf ($ dqlTemplate , PlatformEntity::class);
2765
2765
2766
- $ query = $ this ->getQuery ($ dql , $ data , $ connectionParams , self ::CONNECTION_CONFIGS [$ configName ]);
2766
+ $ connection = $ this ->createConnection ($ connectionParams , self ::CONNECTION_CONFIGS [$ configName ]);
2767
+ $ query = $ this ->getQuery ($ connection , $ dql , $ data );
2767
2768
$ sql = $ query ->getSQL ();
2768
2769
2769
2770
self ::assertIsString ($ sql );
2770
2771
2771
2772
try {
2772
2773
$ result = $ query ->getSingleResult ();
2774
+ $ realResultType = ConstantTypeHelper::getTypeFromValue ($ result );
2775
+ $ inferredType = $ this ->getInferredType ($ query );
2776
+
2773
2777
} catch (Throwable $ e ) {
2774
2778
if ($ expectedInferredType === null ) {
2775
2779
return ;
2776
2780
}
2777
2781
throw $ e ;
2782
+ } finally {
2783
+ $ connection ->close ();
2778
2784
}
2779
2785
2780
- $ realResultType = ConstantTypeHelper::getTypeFromValue ($ result );
2781
- $ inferredType = $ this ->getInferredType ($ query );
2782
-
2783
2786
if ($ expectedInferredType === null ) {
2784
2787
self ::fail (sprintf (
2785
2788
"Expected failure, but none occurred \n\nDriver: %s \nConfig: %s \nDataset: %s \nDQL: %s \nSQL: %s \nReal result: %s \nInferred type: %s \n" ,
@@ -2806,17 +2809,13 @@ private function performDriverTest(
2806
2809
}
2807
2810
2808
2811
/**
2809
- * @param array<string, mixed> $data
2810
2812
* @param array<string, mixed> $connectionParams
2811
2813
* @param array<mixed> $connectionAttributes
2812
- * @return Query<mixed> $query
2813
2814
*/
2814
- private function getQuery (
2815
- string $ dqlTemplate ,
2816
- array $ data ,
2815
+ private function createConnection (
2817
2816
array $ connectionParams ,
2818
2817
array $ connectionAttributes
2819
- ): Query
2818
+ ): Connection
2820
2819
{
2821
2820
$ connection = DriverManager::getConnection ($ connectionParams + [
2822
2821
'user ' => 'root ' ,
@@ -2827,6 +2826,19 @@ private function getQuery(
2827
2826
$ nativeConnection = $ this ->getNativeConnection ($ connection );
2828
2827
$ this ->setupAttributes ($ nativeConnection , $ connectionAttributes );
2829
2828
2829
+ return $ connection ;
2830
+ }
2831
+
2832
+ /**
2833
+ * @param array<string, mixed> $data
2834
+ * @return Query<mixed> $query
2835
+ */
2836
+ private function getQuery (
2837
+ Connection $ connection ,
2838
+ string $ dqlTemplate ,
2839
+ array $ data
2840
+ ): Query
2841
+ {
2830
2842
$ config = new Configuration ();
2831
2843
$ config ->setProxyNamespace ('PHPstan\Doctrine\OrmMatrixProxies ' );
2832
2844
$ config ->setProxyDir ('/tmp/doctrine ' );
0 commit comments