Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

[DoctrineBridge] Add support for doctrine/persistence 4#59575

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromgreg0ire:persistence-4-compat
Jan 25, 2025

Conversation

greg0ire
Copy link
Contributor

@greg0iregreg0ire commentedJan 21, 2025
edited by GromNaN
Loading

v4 provides a guarantee thatManagerRegistry::getManager() returns an entity manager (as opposed to null).

QA
Branch?6.4
Bug fix?no
New feature?no
Deprecations?no
Issuesn/a
LicenseMIT

@carsonbotcarsonbot added this to the6.4 milestoneJan 21, 2025
@greg0ire
Copy link
ContributorAuthor

Let me know if this is the wrong branch, I'm never quite sure for this kind of case with Symfony, but in the past, I think I've been asked to contribute this kind of branch as a patch.

@carsonbotcarsonbot changed the titleAdd support for doctrine/persistence 4[DoctrineBridge] Add support for doctrine/persistence 4Jan 21, 2025
Comment on lines 57 to 59
if (method_exists(ObjectManager::class, 'isUninitializedObject')) {
$this->markTestSkipped('This test is not applicable to doctrine/persistence 4');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How does Persistence 4 behave in this situation? Should we have a test for that as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@derrabusTypeError in the signature of theAbstractManagerRegistry when passingnull as default manager name. AndInvalidArgumentException if there is no manager with that name.

@greg0ire we cannot remove support for the case of having no entity manager. As the ManagerRegistry interface extends ConnectionRegistry in doctrine/persistence (which is a mistake to me, but won't be an easy fix) and we don't have any standalone implementation of ConnectionRegistry, DoctrineBundle will still create a manager registry even when your project enables DBAL and not ORM. And so this case exists (it won't be a case of having no manager registry at all)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the proper fix is to fix the mock of the ManagerRegistry. When passingnull as argument here,getManagerForClass should indeed returnnull butgetManager should throw anInvalidArgumentException (which is already the behavior of doctrine/persistence 2.x and 3.x btw)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the pointers, I'll try that 👍

Copy link
Member

@stofstof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This PR is broken in its current state. It should update mocks to match the actual behavior of doctrine/persistence instead of skipping relevant tests.

-1 for merging it in its current state.

@@ -50,6 +50,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
if (!$options->class || $options->disabled) {
return [];
}
// doctrine/persistence < 4 compat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is not true.$this->getManager can still returnnull (see the implementation of the private method). This method call isnot a call to the doctrine/persistence method.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh right, didn't spot that!

Comment on lines 57 to 59
if (method_exists(ObjectManager::class, 'isUninitializedObject')) {
$this->markTestSkipped('This test is not applicable to doctrine/persistence 4');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@derrabusTypeError in the signature of theAbstractManagerRegistry when passingnull as default manager name. AndInvalidArgumentException if there is no manager with that name.

@greg0ire we cannot remove support for the case of having no entity manager. As the ManagerRegistry interface extends ConnectionRegistry in doctrine/persistence (which is a mistake to me, but won't be an easy fix) and we don't have any standalone implementation of ConnectionRegistry, DoctrineBundle will still create a manager registry even when your project enables DBAL and not ORM. And so this case exists (it won't be a case of having no manager registry at all)

Comment on lines 57 to 59
if (method_exists(ObjectManager::class, 'isUninitializedObject')) {
$this->markTestSkipped('This test is not applicable to doctrine/persistence 4');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the proper fix is to fix the mock of the ManagerRegistry. When passingnull as argument here,getManagerForClass should indeed returnnull butgetManager should throw anInvalidArgumentException (which is already the behavior of doctrine/persistence 2.x and 3.x btw)

@greg0ire
Copy link
ContributorAuthor

@stof I've addressed your review.

Also, I forgot to mention it, butdoctrine/persistence 4 is now indeed installed in at leastthis job

$registry->expects($this->any())
->method('getManager')
->willReturn($manager);
if (method_exists(ObjectManager::class, 'isUninitializedObject')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This should check$manager === null. We don't want to throw when we have an instance.

And I suggest applying this condition even for older versions of doctrine/persistence so that the mock reflects the actual behavior of the class. AbstractManagerRegistry was already throwing an exception in persistence 2.x (I did not check the behavior in 1.x)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I did not check the behavior in 1.x

It is not allowed by Symfony'scomposer.json 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know. That's exactly why I did not check 1.x to see whether our mocks were already wrong back in time or whether they kept emulating the 1.x behavior, because distinguishing those 2 cases does not matter.

greg0ire reacted with thumbs up emoji
@@ -635,6 +639,10 @@ public function testDedicatedEntityManagerNullObject()

public function testEntityManagerNullObject()
{
if (method_exists(ObjectManager::class, 'isUninitializedObject')) {
$this->markTestSkipped('This test is not applicable to doctrine/persistence 4');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Those tests are application, for the same reason that the EntityValueResolver test (and with the same issue about a bad definition of the mock)

@@ -71,6 +71,7 @@ public function validate(mixed $entity, Constraint $constraint)
if ($constraint->em) {
$em = $this->registry->getManager($constraint->em);

// doctrine/persistence < 4 compat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this comment is actually wrong. Older versions ofdoctrine/persistence are also throwing an exception ingetManager

@greg0iregreg0ireforce-pushed thepersistence-4-compat branch 3 times, most recently fromd0069f8 to0b58efaCompareJanuary 23, 2025 14:29
@greg0iregreg0ire requested a review fromstofJanuary 23, 2025 14:49
v4 provides a guarantee that ManagerRegistry::getManager() returns an entitymanager (as opposed to null).The tests need to be adjusted to reflect the behavior of the mocked dependencymore accurately, as it is throwing an exception in case of a null manager forall three supported versions of the library.
@fabpot
Copy link
Member

Thank you@greg0ire.

greg0ire reacted with heart emoji

@fabpotfabpot merged commitef15506 intosymfony:6.4Jan 25, 2025
6 of 7 checks passed
This was referencedJan 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@derrabusderrabusderrabus left review comments

@fabpotfabpotfabpot approved these changes

@stofstofstof approved these changes

@GromNaNGromNaNAwaiting requested review from GromNaN

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

6 participants
@greg0ire@fabpot@GromNaN@stof@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp