Skip to content

Commit ef15506

Browse files
committed
bug #59575 [DoctrineBridge] Add support for doctrine/persistence 4 (greg0ire)
This PR was merged into the 6.4 branch. Discussion ---------- [DoctrineBridge] Add support for doctrine/persistence 4 [v4](https://github.com/doctrine/persistence/blob/4.0.x/UPGRADE.md#upgrade-to-40) provides a guarantee that `ManagerRegistry::getManager()` returns an entity manager (as opposed to null). | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | n/a | License | MIT Commits ------- 6c20172 Add support for doctrine/persistence 4
2 parents 918c7c7 + 6c20172 commit ef15506

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"ext-xml": "*",
4040
"friendsofphp/proxy-manager-lts": "^1.0.2",
4141
"doctrine/event-manager": "^1.2|^2",
42-
"doctrine/persistence": "^2.5|^3.1",
42+
"doctrine/persistence": "^2.5|^3.1|^4",
4343
"twig/twig": "^2.13|^3.0.4",
4444
"psr/cache": "^2.0|^3.0",
4545
"psr/clock": "^1.0",

src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,13 @@ private function createRegistry(?ObjectManager $manager = null): ManagerRegistry
415415
->method('getManagerForClass')
416416
->willReturn($manager);
417417

418-
$registry->expects($this->any())
419-
->method('getManager')
420-
->willReturn($manager);
418+
if (null === $manager) {
419+
$registry->method('getManager')
420+
->willThrowException(new \InvalidArgumentException());
421+
} else {
422+
$registry->method('getManager')->willReturn($manager);
423+
}
424+
421425

422426
return $registry;
423427
}

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,16 @@ protected function setUp(): void
7676
protected function createRegistryMock($em = null)
7777
{
7878
$registry = $this->createMock(ManagerRegistry::class);
79-
$registry->expects($this->any())
80-
->method('getManager')
81-
->with($this->equalTo(self::EM_NAME))
82-
->willReturn($em);
79+
80+
if (null === $em) {
81+
$registry->method('getManager')
82+
->with($this->equalTo(self::EM_NAME))
83+
->willThrowException(new \InvalidArgumentException());
84+
} else {
85+
$registry->method('getManager')
86+
->with($this->equalTo(self::EM_NAME))
87+
->willReturn($em);
88+
}
8389

8490
return $registry;
8591
}

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public function validate(mixed $entity, Constraint $constraint)
6969
}
7070

7171
if ($constraint->em) {
72-
$em = $this->registry->getManager($constraint->em);
73-
74-
if (!$em) {
75-
throw new ConstraintDefinitionException(sprintf('Object manager "%s" does not exist.', $constraint->em));
72+
try {
73+
$em = $this->registry->getManager($constraint->em);
74+
} catch (\InvalidArgumentException $e) {
75+
throw new ConstraintDefinitionException(sprintf('Object manager "%s" does not exist.', $constraint->em), 0, $e);
7676
}
7777
} else {
7878
$em = $this->registry->getManagerForClass($entity::class);

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.1",
2020
"doctrine/event-manager": "^1.2|^2",
21-
"doctrine/persistence": "^2.5|^3.1",
21+
"doctrine/persistence": "^2.5|^3.1|^4",
2222
"symfony/deprecation-contracts": "^2.5|^3",
2323
"symfony/polyfill-ctype": "~1.8",
2424
"symfony/polyfill-mbstring": "~1.0",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy