Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 3.2.0 into 4.0.x #11473

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,27 @@ class EntityManager implements EntityManagerInterface
/**
* The metadata factory, used to retrieve the ORM metadata of entity classes.
*/
private readonly ClassMetadataFactory $metadataFactory;
private ClassMetadataFactory $metadataFactory;

/**
* The UnitOfWork used to coordinate object-level transactions.
*/
private readonly UnitOfWork $unitOfWork;
private UnitOfWork $unitOfWork;

/**
* The event manager that is the central point of the event system.
*/
private readonly EventManager $eventManager;
private EventManager $eventManager;

/**
* The proxy factory used to create dynamic proxies.
*/
private readonly ProxyFactory $proxyFactory;
private ProxyFactory $proxyFactory;

/**
* The repository factory used to create dynamic repositories.
*/
private readonly RepositoryFactory $repositoryFactory;
private RepositoryFactory $repositoryFactory;

/**
* The expression builder instance used to generate query expressions.
Expand Down Expand Up @@ -112,8 +112,8 @@ class EntityManager implements EntityManagerInterface
* @param Connection $conn The database connection used by the EntityManager.
*/
public function __construct(
private readonly Connection $conn,
private readonly Configuration $config,
private Connection $conn,
private Configuration $config,
EventManager|null $eventManager = null,
) {
if (! $config->getMetadataDriverImpl()) {
Expand Down
35 changes: 35 additions & 0 deletions tests/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\EntityManagerClosed;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
Expand All @@ -21,7 +22,9 @@
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use ReflectionProperty;
use stdClass;
use Symfony\Component\VarExporter\LazyGhostTrait;
use TypeError;

class EntityManagerTest extends OrmTestCase
Expand Down Expand Up @@ -172,4 +175,36 @@ public function testWrapInTransactionReThrowsThrowables(): void
self::assertFalse($this->entityManager->isOpen());
}
}

/** Resetting the EntityManager relies on lazy objects until https://github.com/doctrine/orm/issues/5933 is resolved */
public function testLazyGhostEntityManager(): void
{
$em = new class () extends EntityManager {
use LazyGhostTrait;

public function __construct()
{
}
};

$em = $em::createLazyGhost(static function ($em): void {
$r = new ReflectionProperty(EntityManager::class, 'unitOfWork');
$r->setValue($em, new class () extends UnitOfWork {
public function __construct()
{
}

public function clear(): void
{
}
});
});

$this->assertTrue($em->isOpen());
$em->close();
$this->assertFalse($em->isOpen());

$em->resetLazyObject();
$this->assertTrue($em->isOpen());
}
}
Loading