Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0b58efa

Browse filesBrowse files
committed
Add support for doctrine/persistence 4
v4 provides a guarantee that ManagerRegistry::getManager() returns an entity manager (as opposed to null). The tests need to be adjusted to reflect the behavior of the mocked dependency more accurately, as it is throwing an exception in case of a null manager for all three supported versions of the library.
1 parent 2fd8b08 commit 0b58efa
Copy full SHA for 0b58efa

File tree

5 files changed

+27
-13
lines changed
Filter options

5 files changed

+27
-13
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1-1
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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php
+7-3
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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php
+10-4
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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
+8-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ 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(
76+
sprintf('Object manager "%s" does not exist.', $constraint->em),
77+
0,
78+
$e
79+
);
7680
}
7781
} else {
7882
$em = $this->registry->getManagerForClass($entity::class);

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+1-1
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.