1010use Doctrine \DBAL \Result ;
1111use Doctrine \ORM \EntityManagerInterface ;
1212use Doctrine \ORM \Events ;
13- use Doctrine \ORM \Exception \ORMException ;
1413use Doctrine \ORM \Internal \Hydration \AbstractHydrator ;
1514use Doctrine \ORM \Query \ResultSetMapping ;
1615use Doctrine \Tests \Models \Hydration \SimpleEntity ;
1716use Doctrine \Tests \OrmFunctionalTestCase ;
17+ use LogicException ;
1818use PHPUnit \Framework \Attributes \CoversClass ;
1919use PHPUnit \Framework \Attributes \Group ;
2020use PHPUnit \Framework \MockObject \MockObject ;
@@ -27,7 +27,7 @@ class AbstractHydratorTest extends OrmFunctionalTestCase
2727 private EventManager &MockObject $ mockEventManager ;
2828 private Result &MockObject $ mockResult ;
2929 private ResultSetMapping &MockObject $ mockResultMapping ;
30- private AbstractHydrator & MockObject $ hydrator ;
30+ private DummyHydrator $ hydrator ;
3131
3232 protected function setUp (): void
3333 {
@@ -52,11 +52,7 @@ protected function setUp(): void
5252 ->method ('fetchAssociative ' )
5353 ->willReturn (false );
5454
55- $ this ->hydrator = $ this
56- ->getMockBuilder (AbstractHydrator::class)
57- ->onlyMethods (['hydrateAllData ' ])
58- ->setConstructorArgs ([$ mockEntityManagerInterface ])
59- ->getMock ();
55+ $ this ->hydrator = new DummyHydrator ($ mockEntityManagerInterface );
6056 }
6157
6258 /**
@@ -142,13 +138,9 @@ public function testHydrateAllClearsAllAttachedListenersEvenOnError(): void
142138 $ this ->assertTrue ($ eventListenerHasBeenRegistered );
143139 });
144140
145- $ this
146- ->hydrator
147- ->expects (self ::once ())
148- ->method ('hydrateAllData ' )
149- ->willThrowException ($ this ->createStub (ORMException::class));
141+ $ this ->hydrator ->throwException = true ;
150142
151- $ this ->expectException (ORMException ::class);
143+ $ this ->expectException (LogicException ::class);
152144 $ this ->hydrator ->hydrateAll ($ this ->mockResult , $ this ->mockResultMapping );
153145 }
154146
@@ -181,3 +173,18 @@ public function testToIterableIfYieldAndBreakBeforeFinishAlwaysCleansUp(): void
181173 self ::assertCount (0 , $ evm ->getListeners (Events::onClear));
182174 }
183175}
176+
177+ class DummyHydrator extends AbstractHydrator
178+ {
179+ public bool $ throwException = false ;
180+
181+ /** @return array{} */
182+ protected function hydrateAllData (): array
183+ {
184+ if ($ this ->throwException ) {
185+ throw new LogicException ();
186+ }
187+
188+ return [];
189+ }
190+ }
0 commit comments