Skip to content

Commit 7604bc1

Browse files
janedbalondrejmirtes
authored andcommitted
Support class-string<T> in ->from
1 parent 4547795 commit 7604bc1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Type/Doctrine/ArgumentsProcessor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public function processArgs(
4747
$args[] = $array;
4848
continue;
4949
}
50+
51+
if ($value->isClassStringType()->yes() && count($value->getClassStringObjectType()->getObjectClassNames()) === 1) {
52+
$args[] = $value->getClassStringObjectType()->getObjectClassNames()[0];
53+
continue;
54+
}
55+
5056
if (count($value->getConstantScalarValues()) !== 1) {
5157
throw new DynamicQueryBuilderArgumentException();
5258
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,33 @@ public function testDynamicMethodCall(
233233
assertType('mixed', $result);
234234
}
235235

236+
237+
/**
238+
* @param class-string<Many> $many
239+
*/
240+
public function testRegularClassString(EntityManagerInterface $em, string $many)
241+
{
242+
$result = $em->createQueryBuilder()
243+
->select("m")
244+
->from($many, 'm')
245+
->getQuery()
246+
->getResult();
247+
248+
assertType('list<QueryResult\Entities\Many>', $result);
249+
}
250+
/**
251+
* @param class-string<T> $many
252+
* @template T of Many
253+
*/
254+
public function testTemplatedClassString(EntityManagerInterface $em, string $many)
255+
{
256+
$result = $em->createQueryBuilder()
257+
->select("m")
258+
->from($many, 'm')
259+
->getQuery()
260+
->getResult();
261+
262+
assertType('list<QueryResult\Entities\Many>', $result);
263+
}
264+
236265
}

0 commit comments

Comments
 (0)