Skip to content

[WCM] Deleting save and remove methods from repositories #1328

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

Conversation

mdoutreluingne
Copy link
Contributor

Fix #1327

In this PR I've removed the save and remove methods from the repositories, for the reasons explained here #1327.

( The add method has been renamed to save, here #1204 )

Reviews welcome!

@mdoutreluingne mdoutreluingne changed the title Deleting save and remove methods from repositories [WIP] Deleting save and remove methods from repositories Jun 24, 2023
@mdoutreluingne
Copy link
Contributor Author

mdoutreluingne commented Jun 25, 2023

It seems that the red tests are linked to my PR. However, I want to correct the tests but I am unable them.

Locally I still have this error Compile Error: Cannot use Doctrine\ORM\EntityManagerInterface as EntityManagerInterface because the name is already in use that I am unable correct them .

Can you please help me?

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! I just dropped a hint about the failed test

@mdoutreluingne
Copy link
Contributor Author

It looks like the other failed test came from it_generates_basic_crud.php, I'll try to fix that tomorrow

@mdoutreluingne
Copy link
Contributor Author

mdoutreluingne commented Jun 29, 2023

Finally, the remaining failed test came from it_generates_crud_using_custom_repository on the assert assertFileEquals because the files WithCustomRepository.php and SweetFoodController.php were not identical due to the renderForm methods in WithCustomRepository.php for the route names app_sweet_food_new and app_sweet_food_edit.

When I ran the tests locally, I didn't get this error again. It's strange because after committing and pushing on the repository, the it_generates_crud_using_custom_repository test still fails, whereas locally I don't get any more errors concerning this test.

I noticed that this test also failed on the PRs(#1330, #1325).

Would you have any suggestions for correcting this test?

@weaverryan
Copy link
Member

The tests can be sensitive. That's partly by design, but they can be a pain... especially when it comes to different Symfony versions. Here's what I'm thinking:

A) Duplicate WithCustomRepository.php to create a new WithCustomRepositoryLegacy.php that includes the renderForm() version.

B) In MakeCrudTest, dynamically choose WithCustomRepository.php vs WithCustomRepositoryLegacy.php in the assertFileEquals() by checking Kernel::VERSION_ID < 60200. Something like:

- sprintf('%s/fixtures/%s', \dirname(__DIR__), 'make-crud/expected/WithCustomRepository.php'),
+ sprintf('%s/fixtures/make-crud/expected/WithCustomRepository%s.php', \dirname(__DIR__), Kernel::VERSION_ID < 60200 ? 'Legacy' : ''),

Let me know if that helps :)

@mdoutreluingne
Copy link
Contributor Author

Unfortunately, the tests failed globally (1 test failed when installing symfony/console), I don't know why it compares render() and renderForm() when WithCustomRepository.php is chosen dynamically.

One thing to note: the last 2 tests failed on the index and show route names, while the other 2 failed on the new and edit route names.

@weaverryan
Copy link
Member

My code suggestion for checking the Symfony version was slightly wrong - I just pushed the fix for it. Let's see what the tests think now :)

@mdoutreluingne
Copy link
Contributor Author

The tests were successful ! :)

@weaverryan Thanks for your help

I didn't understand why you replaced renderForm() by render() for the route name index and show in WithCustomRepositoryLegacy.php, which should normally be the version with renderForm()

@mdoutreluingne mdoutreluingne changed the title [WIP] Deleting save and remove methods from repositories [WCM] Deleting save and remove methods from repositories Jul 5, 2023
@weaverryan
Copy link
Member

I didn't understand why you replaced renderForm() by render() for the route name index and show in WithCustomRepositoryLegacy.php, which should normally be the version with renderForm()

Even back when renderForm() existed and was the correct solution, there was no reason to call renderForm() if you weren't passing a form into the template. So index and show have always generated as render().

Anyway, tests green now! Woo!

@weaverryan
Copy link
Member

Thanks Maxime!

@weaverryan weaverryan merged commit 9d0003b into symfony:main Jul 10, 2023
@mdoutreluingne mdoutreluingne deleted the deleting_add_remove_methods_repositories branch July 10, 2023 19:00
constantable added a commit to constantable/maker-bundle that referenced this pull request Jul 11, 2023
weaverryan added a commit that referenced this pull request Jul 18, 2023
This PR was squashed before being merged into the 1.0-dev branch.

Discussion
----------

Ignore use statement generator duplicates

Follow #1328 (comment)

Following weaverryan's idea I've improved `UseStatementGenerator` in this PR to ignore duplicates.

Commits
-------

1bfaf30 Ignore use statement generator duplicates
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.

Do not flush in the repository
2 participants