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

Suggestion: Deprecate grabEntityFromRepository() and grabEntitiesFromRepository() #22

Closed
ThomasLandauer opened this issue Dec 2, 2020 · 1 comment · Fixed by #68
Closed

Comments

@ThomasLandauer
Copy link
Member

My question is: What's the benefit of doing

$greenFoo = $I->grabEntityFromRepository(Foo::class, ['color' => 'green']);

over doing

$greenFoo = $this->fooRepository->findOneBy(['color' => 'green']);

(To be fair, in the second sample, I omitted the boilerplate code inside _before(): $this->fooRepository = $I->grabService(FooRepository::class);.)

Shouldn't Codeception concentrate on providing handy methods that make otherwise complicated stuff easier, rather than "copying" methods which are already easy?

Even worse, in this case, using Codeception's methods actually makes it harder for many people, since they have unintended side-effects that are (a) undocumented and (b) counter-intuitive. So just stopping people from using them, would immediately resolve at least 4 issues:

So wouldn't it be easier for everybody to just deprecate those methods? And instead of making people learn something new (which eventually doesn't work as they expect), just show them how easy it is to go with Doctrine's built-in repository methods which they already know?

@jannes-io
Copy link

I personally agree that in Symfony, the process is simplified to grab an actual repository. But the doctrine2 module can be used without Symfony. In that use-case you'd need to construct your own instances of EntityRepository which always needs the entity manager and all of its dependencies. So these helper functions are actually more-or-less what a user would have to do without Symfony.

Another big difference is that those working in Symfony would 9/10 use ServiceEntityRepository instead of just EntityRepository. So providing a simple API to query entities can be helpful for those who want quick tests.

Perhaps just modify the documentation to highlight that usage of actual repositories to grab entities is preferred over using the helper grabbers?

ThomasLandauer added a commit to ThomasLandauer/module-doctrine2 that referenced this issue Mar 13, 2023
Info is taken from Codeception#22 (comment)

In case of merge conflict: This is meant to go between "Description" and "Public Properties"

TODO after this is merged: Add a link from the three `grab` methods to this section
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 a pull request may close this issue.

2 participants