@@ -20,20 +20,19 @@ class HintDrivenSqlWalkerTest extends TestCase
2020{
2121
2222 /**
23+ * @param callable(EntityManager):Query $queryCallback
2324 * @dataProvider walksProvider
2425 */
2526 public function testWalker (
26- string $ dql ,
27+ callable $ queryCallback ,
2728 string $ handlerClass ,
2829 mixed $ hintValue ,
2930 string $ expectedSql ,
3031 ): void
3132 {
3233 $ entityManagerMock = $ this ->createEntityManagerMock ();
3334
34- $ query = new Query ($ entityManagerMock );
35- $ query ->setDQL ($ dql );
36-
35+ $ query = $ queryCallback ($ entityManagerMock );
3736 $ query ->setHint (Query::HINT_CUSTOM_OUTPUT_WALKER , HintDrivenSqlWalker::class);
3837 $ query ->setHint ($ handlerClass , $ hintValue );
3938 $ producedSql = $ query ->getSQL ();
@@ -42,39 +41,52 @@ public function testWalker(
4241 }
4342
4443 /**
45- * @return Generator<string, array{string , class-string<HintHandler>, mixed, string}>
44+ * @return Generator<string, array{callable(EntityManager):Query , class-string<HintHandler>, mixed, string}>
4645 */
4746 public static function walksProvider (): iterable
4847 {
4948 $ selectDql = sprintf ('SELECT w FROM %s w ' , DummyEntity::class);
5049
5150 yield 'Lowercase select ' => [
52- $ selectDql ,
51+ static fn ( EntityManager $ entityManager ): Query => $ entityManager -> createQuery ( $ selectDql) ,
5352 LowercaseSelectHintHandler::class,
5453 null ,
5554 'select d0_.id AS id_0 FROM dummy_entity d0_ ' ,
5655 ];
5756
5857 yield 'Comment whole sql - select ' => [
59- $ selectDql ,
58+ static fn ( EntityManager $ entityManager ): Query => $ entityManager -> createQuery ( $ selectDql) ,
6059 CommentWholeSqlHintHandler::class,
6160 'custom comment ' ,
6261 'SELECT d0_.id AS id_0 FROM dummy_entity d0_ -- custom comment ' ,
6362 ];
6463
6564 yield 'Comment whole sql - update ' => [
66- sprintf ('UPDATE %s w SET w.id = 1 ' , DummyEntity::class),
65+ static fn ( EntityManager $ entityManager ): Query => $ entityManager -> createQuery ( sprintf ('UPDATE %s w SET w.id = 1 ' , DummyEntity::class) ),
6766 CommentWholeSqlHintHandler::class,
6867 'custom comment ' ,
6968 'UPDATE dummy_entity SET id = 1 -- custom comment ' ,
7069 ];
7170
7271 yield 'Comment whole sql - delete ' => [
73- sprintf ('DELETE FROM %s w ' , DummyEntity::class),
72+ static fn ( EntityManager $ entityManager ): Query => $ entityManager -> createQuery ( sprintf ('DELETE FROM %s w ' , DummyEntity::class) ),
7473 CommentWholeSqlHintHandler::class,
7574 'custom comment ' ,
7675 'DELETE FROM dummy_entity -- custom comment ' ,
7776 ];
77+
78+ yield 'Comment whole sql with LIMIT ' => [
79+ static function (EntityManager $ entityManager ): Query {
80+ return $ entityManager ->createQueryBuilder ()
81+ ->select ('w ' )
82+ ->from (DummyEntity::class, 'w ' )
83+ ->setMaxResults (1 )
84+ ->getQuery ();
85+ },
86+ CommentWholeSqlHintHandler::class,
87+ 'custom comment ' ,
88+ 'SELECT d0_.id AS id_0 FROM dummy_entity d0_ LIMIT 1 -- custom comment ' ,
89+ ];
7890 }
7991
8092 private function createEntityManagerMock (): EntityManager
0 commit comments