File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -547,6 +547,10 @@ public function getFirstResult(): int
547547 */
548548 public function setMaxResults (int |null $ maxResults ): static
549549 {
550+ if ($ this ->type === QueryType::Delete || $ this ->type === QueryType::Update) {
551+ throw new RuntimeException ('Setting a limit is not supported for delete or update queries. ' );
552+ }
553+
550554 $ this ->maxResults = $ maxResults ;
551555
552556 return $ this ;
Original file line number Diff line number Diff line change 2727use PHPUnit \Framework \Attributes \Group ;
2828use PHPUnit \Framework \Attributes \WithoutErrorHandler ;
2929use PHPUnit \Framework \TestCase ;
30+ use RuntimeException ;
3031
3132use function array_filter ;
3233use function class_exists ;
@@ -72,6 +73,26 @@ public function testDeleteSetsType(): void
7273 $ this ->assertValidQueryBuilder ($ qb , 'DELETE Doctrine\Tests\Models\CMS\CmsUser u ' );
7374 }
7475
76+ public function testDeleteWithLimitNotSupported (): void
77+ {
78+ $ this ->expectException (RuntimeException::class);
79+ $ this ->expectExceptionMessage ('Setting a limit is not supported for delete or update queries. ' );
80+
81+ $ this ->entityManager ->createQueryBuilder ()
82+ ->delete (CmsUser::class, 'c ' )
83+ ->setMaxResults (1 );
84+ }
85+
86+ public function testUpdateWithLimitNotSupported (): void
87+ {
88+ $ this ->expectException (RuntimeException::class);
89+ $ this ->expectExceptionMessage ('Setting a limit is not supported for delete or update queries. ' );
90+
91+ $ this ->entityManager ->createQueryBuilder ()
92+ ->update (CmsUser::class, 'c ' )
93+ ->setMaxResults (1 );
94+ }
95+
7596 public function testUpdateSetsType (): void
7697 {
7798 $ qb = $ this ->entityManager ->createQueryBuilder ()
You can’t perform that action at this time.
0 commit comments