Skip to content

Commit baf96cd

Browse files
Remove readonly modifier from EntityManager
1 parent dbfe47b commit baf96cd

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

Diff for: src/EntityManager.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,27 @@ class EntityManager implements EntityManagerInterface
6363
/**
6464
* The metadata factory, used to retrieve the ORM metadata of entity classes.
6565
*/
66-
private readonly ClassMetadataFactory $metadataFactory;
66+
private ClassMetadataFactory $metadataFactory;
6767

6868
/**
6969
* The UnitOfWork used to coordinate object-level transactions.
7070
*/
71-
private readonly UnitOfWork $unitOfWork;
71+
private UnitOfWork $unitOfWork;
7272

7373
/**
7474
* The event manager that is the central point of the event system.
7575
*/
76-
private readonly EventManager $eventManager;
76+
private EventManager $eventManager;
7777

7878
/**
7979
* The proxy factory used to create dynamic proxies.
8080
*/
81-
private readonly ProxyFactory $proxyFactory;
81+
private ProxyFactory $proxyFactory;
8282

8383
/**
8484
* The repository factory used to create dynamic repositories.
8585
*/
86-
private readonly RepositoryFactory $repositoryFactory;
86+
private RepositoryFactory $repositoryFactory;
8787

8888
/**
8989
* The expression builder instance used to generate query expressions.
@@ -112,8 +112,8 @@ class EntityManager implements EntityManagerInterface
112112
* @param Connection $conn The database connection used by the EntityManager.
113113
*/
114114
public function __construct(
115-
private readonly Connection $conn,
116-
private readonly Configuration $config,
115+
private Connection $conn,
116+
private Configuration $config,
117117
EventManager|null $eventManager = null,
118118
) {
119119
if (! $config->getMetadataDriverImpl()) {

Diff for: tests/Tests/ORM/EntityManagerTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\Common\EventManager;
88
use Doctrine\DBAL\Connection;
99
use Doctrine\ORM\Configuration;
10+
use Doctrine\ORM\EntityManager;
1011
use Doctrine\ORM\EntityManagerInterface;
1112
use Doctrine\ORM\Exception\EntityManagerClosed;
1213
use Doctrine\ORM\Mapping\ClassMetadataFactory;
@@ -21,7 +22,9 @@
2122
use Generator;
2223
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\Attributes\Group;
25+
use ReflectionProperty;
2426
use stdClass;
27+
use Symfony\Component\VarExporter\LazyGhostTrait;
2528
use TypeError;
2629

2730
class EntityManagerTest extends OrmTestCase
@@ -172,4 +175,36 @@ public function testWrapInTransactionReThrowsThrowables(): void
172175
self::assertFalse($this->entityManager->isOpen());
173176
}
174177
}
178+
179+
/** Resetting the EntityManager relies on lazy objects until https://github.com/doctrine/orm/issues/5933 is resolved */
180+
public function testLazyGhostEntityManager(): void
181+
{
182+
$em = new class () extends EntityManager {
183+
use LazyGhostTrait;
184+
185+
public function __construct()
186+
{
187+
}
188+
};
189+
190+
$em = $em::createLazyGhost(static function ($em): void {
191+
$r = new ReflectionProperty(EntityManager::class, 'unitOfWork');
192+
$r->setValue($em, new class () extends UnitOfWork {
193+
public function __construct()
194+
{
195+
}
196+
197+
public function clear(): void
198+
{
199+
}
200+
});
201+
});
202+
203+
$this->assertTrue($em->isOpen());
204+
$em->close();
205+
$this->assertFalse($em->isOpen());
206+
207+
$em->resetLazyObject();
208+
$this->assertTrue($em->isOpen());
209+
}
175210
}

0 commit comments

Comments
 (0)