Skip to content

Commit d095b26

Browse files
committed
Try prevent too many connections
1 parent 8155c07 commit d095b26

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,23 +2763,26 @@ private function performDriverTest(
27632763
$connectionParams = ['driver' => $driver] + $this->getConnectionParamsForDriver($driver);
27642764
$dql = sprintf($dqlTemplate, PlatformEntity::class);
27652765

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);
27672768
$sql = $query->getSQL();
27682769

27692770
self::assertIsString($sql);
27702771

27712772
try {
27722773
$result = $query->getSingleResult();
2774+
$realResultType = ConstantTypeHelper::getTypeFromValue($result);
2775+
$inferredType = $this->getInferredType($query);
2776+
27732777
} catch (Throwable $e) {
27742778
if ($expectedInferredType === null) {
27752779
return;
27762780
}
27772781
throw $e;
2782+
} finally {
2783+
$connection->close();
27782784
}
27792785

2780-
$realResultType = ConstantTypeHelper::getTypeFromValue($result);
2781-
$inferredType = $this->getInferredType($query);
2782-
27832786
if ($expectedInferredType === null) {
27842787
self::fail(sprintf(
27852788
"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(
28062809
}
28072810

28082811
/**
2809-
* @param array<string, mixed> $data
28102812
* @param array<string, mixed> $connectionParams
28112813
* @param array<mixed> $connectionAttributes
2812-
* @return Query<mixed> $query
28132814
*/
2814-
private function getQuery(
2815-
string $dqlTemplate,
2816-
array $data,
2815+
private function createConnection(
28172816
array $connectionParams,
28182817
array $connectionAttributes
2819-
): Query
2818+
): Connection
28202819
{
28212820
$connection = DriverManager::getConnection($connectionParams + [
28222821
'user' => 'root',
@@ -2827,6 +2826,19 @@ private function getQuery(
28272826
$nativeConnection = $this->getNativeConnection($connection);
28282827
$this->setupAttributes($nativeConnection, $connectionAttributes);
28292828

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+
{
28302842
$config = new Configuration();
28312843
$config->setProxyNamespace('PHPstan\Doctrine\OrmMatrixProxies');
28322844
$config->setProxyDir('/tmp/doctrine');

0 commit comments

Comments
 (0)