Skip to content

Lazily resolve ManagerRegistry in EntityManagerProvider #664

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

Merged
merged 3 commits into from
May 21, 2025

Conversation

LegendEffects
Copy link
Contributor

Fixes an issue where a connection will always be attempted when running any command (including package discovery) if there are custom types installed.

#663

public function getDefaultManager(): EntityManagerInterface
{
$entityManager = $this->managerRegistry->getManager();
$entityManager = $this->getManagerRegistry()->getManager();
Copy link
Contributor

Choose a reason for hiding this comment

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

@LegendEffects
Following the doctrine filosophy you shouldn't cache the get manager.
Just do the app(ManagerRegistry::class) or $this->container->make(ManagerRegistry::class) where you need it.

The make not gonna create another object, it's defined as singleton it's gonna inject previously created manager registry.

Why?
Because you gonna have control over the injected Manager Registry object.
You want to have this control for tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I was just keeping the same code flow as before, I avoided using the app helper as there was no other instances of it being used in the package

@TomHAnderson
Copy link
Contributor

I've updated the test runner in #665
Please merge or rebase this PR with 3.1.x

Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.93%. Comparing base (526428a) to head (791389c).
Report is 4 commits behind head on 3.1.x.

Files with missing lines Patch % Lines
src/Console/EntityManagerProvider.php 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              3.1.x     #664   +/-   ##
=========================================
  Coverage     80.93%   80.93%           
  Complexity      495      495           
=========================================
  Files            73       73           
  Lines          1631     1631           
=========================================
  Hits           1320     1320           
  Misses          311      311           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TomHAnderson
Copy link
Contributor

Tests fail because the new code in this patch isn't covered

@LegendEffects
Copy link
Contributor Author

There are no tests present for the entire Console namespace, adding tests to this would also pretty much just be testing the PSR container so feels pointless.

@TomHAnderson
Copy link
Contributor

Thanks for the feedback. I agree.

@TomHAnderson TomHAnderson merged commit 3a38bf9 into laravel-doctrine:3.1.x May 21, 2025
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants