File tree Expand file tree Collapse file tree 3 files changed +17
-23
lines changed Expand file tree Collapse file tree 3 files changed +17
-23
lines changed Original file line number Diff line number Diff line change 44
55namespace Doctrine \Performance \Mock ;
66
7- use Doctrine \DBAL \LockMode ;
8- use Doctrine \ORM \Mapping \AssociationMapping ;
7+ use Doctrine \ORM \Mapping \ClassMetadata ;
98use Doctrine \ORM \Persisters \Entity \BasicEntityPersister ;
109
1110/**
1211 * A persister that doesn't actually load given objects
1312 */
1413class NonLoadingPersister extends BasicEntityPersister
1514{
16- public function __construct ()
17- {
15+ public function __construct (
16+ ClassMetadata $ class ,
17+ ) {
18+ $ this ->class = $ class ;
1819 }
1920
20- /**
21- * {@inheritDoc}
22- */
23- public function load (
24- array $ criteria ,
25- object |null $ entity = null ,
26- AssociationMapping |null $ assoc = null ,
27- array $ hints = [],
28- LockMode |int |null $ lockMode = null ,
29- int |null $ limit = null ,
30- array |null $ orderBy = null ,
31- ): object |null {
32- return $ entity ;
21+ public function loadById (array $ identifier , object |null $ entity = null ): object |null
22+ {
23+ return $ entity ?? new ($ this ->class ->name )();
3324 }
3425}
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public function getClassMetadata(string $className): ClassMetadata
5757
5858 public function getUnitOfWork (): UnitOfWork
5959 {
60- return new NonProxyLoadingUnitOfWork ();
60+ return new NonProxyLoadingUnitOfWork ($ this );
6161 }
6262
6363 public function getCache (): Cache |null
Original file line number Diff line number Diff line change 44
55namespace Doctrine \Performance \Mock ;
66
7+ use Doctrine \ORM \EntityManagerInterface ;
78use Doctrine \ORM \UnitOfWork ;
89
910/**
1011 * An unit of work mock that prevents lazy-loading of proxies
1112 */
1213class NonProxyLoadingUnitOfWork extends UnitOfWork
1314{
14- private NonLoadingPersister $ entityPersister ;
15+ /** @var array<class-string, NonLoadingPersister> */
16+ private array $ entityPersisters = [];
1517
16- public function __construct ()
17- {
18- $ this -> entityPersister = new NonLoadingPersister ();
18+ public function __construct (
19+ private EntityManagerInterface $ entityManager ,
20+ ) {
1921 }
2022
2123 public function getEntityPersister (string $ entityName ): NonLoadingPersister
2224 {
23- return $ this ->entityPersister ;
25+ return $ this ->entityPersisters [$ entityName ]
26+ ??= new NonLoadingPersister ($ this ->entityManager ->getClassMetadata ($ entityName ));
2427 }
2528}
You can’t perform that action at this time.
0 commit comments