Skip to content

Commit f928aa2

Browse files
committed
Merge remote-tracking branch 'origin/1.3.x' into 1.4.x
2 parents 19d33c4 + 08b193c commit f928aa2

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/Type/Doctrine/CreateQueryDynamicReturnTypeExtension.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\ORM\EntityManagerInterface;
1010
use Doctrine\ORM\ORMException;
1111
use Doctrine\ORM\Query;
12+
use Doctrine\Persistence\Mapping\MappingException;
1213
use PhpParser\Node\Expr\MethodCall;
1314
use PHPStan\Analyser\Scope;
1415
use PHPStan\Reflection\MethodReflection;
@@ -87,7 +88,7 @@ public function getTypeFromMethodCall(
8788
try {
8889
$query = $em->createQuery($queryString);
8990
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
90-
} catch (ORMException | DBALException | NewDBALException | CommonException $e) {
91+
} catch (ORMException | DBALException | NewDBALException | CommonException | MappingException $e) {
9192
return new QueryType($queryString, null, null);
9293
} catch (AssertionError $e) {
9394
return new QueryType($queryString, null, null);

src/Type/Doctrine/QueryBuilder/QueryBuilderGetQueryDynamicReturnTypeExtension.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\DBALException;
88
use Doctrine\ORM\EntityManagerInterface;
99
use Doctrine\ORM\ORMException;
10+
use Doctrine\Persistence\Mapping\MappingException;
1011
use PhpParser\Node\Expr\MethodCall;
1112
use PhpParser\Node\Identifier;
1213
use PHPStan\Analyser\Scope;
@@ -195,7 +196,7 @@ private function getQueryType(string $dql): Type
195196
try {
196197
$query = $em->createQuery($dql);
197198
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
198-
} catch (ORMException | DBALException | CommonException $e) {
199+
} catch (ORMException | DBALException | CommonException | MappingException $e) {
199200
return new QueryType($dql, null);
200201
} catch (AssertionError $e) {
201202
return new QueryType($dql, null);

tests/Type/Doctrine/data/QueryResult/createQuery.php

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function testQueryTypeSimpleArray(EntityManagerInterface $em): void
3232
assertType('Doctrine\ORM\Query<null, array{simpleArrayColumn: list<string>}>', $query);
3333
}
3434

35+
public function testMappingError(EntityManagerInterface $em): void
36+
{
37+
$query = $em->createQuery('SELECT u.foo FROM ' . CreateQuery::class . ' u');
38+
39+
assertType('Doctrine\ORM\Query<mixed, mixed>', $query);
40+
}
41+
3542
public function testQueryResultTypeIsMixedWhenDQLIsNotKnown(EntityManagerInterface $em, string $dql): void
3643
{
3744
$query = $em->createQuery($dql);

tests/Type/Doctrine/data/QueryResult/queryBuilderGetQuery.php

+15
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,19 @@ public function testTemplatedClassString(EntityManagerInterface $em, string $man
282282
assertType('list<QueryResult\Entities\Many>', $result);
283283
}
284284

285+
286+
/**
287+
* @param class-string<self> $classString
288+
*/
289+
public function testNonEntityClassString(EntityManagerInterface $em, string $classString)
290+
{
291+
$result = $em->createQueryBuilder()
292+
->select("m")
293+
->from($classString, 'm')
294+
->getQuery()
295+
->getResult();
296+
297+
assertType('mixed', $result);
298+
}
299+
285300
}

0 commit comments

Comments
 (0)