-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
[make:reset-password] Translate exception reasons provided by ResetPasswordBundle #1059
[make:reset-password] Translate exception reasons provided by ResetPasswordBundle #1059
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :)
Thank you for the review, @codedmonkey ! |
src/Maker/MakeResetPassword.php
Outdated
|
||
$optionalTranslatorParams = []; | ||
if ($isTranslatorAvailable = interface_exists(TranslatorInterface::class)) { | ||
$optionalTranslatorParams['translator_class_details'] = $generator->createClassNameDetails(TranslatorInterface::class, '\\'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fairly speaking, I'm not sure we need to create class name details for translator as well. I just did the same way password_hasher_class_details
is implemented. Should we just hardcode translator class instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I would accept it like this but that would be cleaner, the translator is rarely variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for sharing some thoughts about it! I made this change, the logic would be simpler this way unless we really need to use some benefits of that createClassNameDetails()
https://github.com/symfonycasts/reset-password-bundle/releases/tag/v1.12.0 implements translation support for translations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thanks @bocharsky-bw - this will pair nicely with the work you did over in ResetPasswordBundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bocharsky-bw I think the <?php PHP_EOL ?>
is causing issues on windows (appveyor tests).. try removing those EOL tags and we should be good to go
src/Maker/MakeResetPassword.php
Outdated
@@ -111,6 +112,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void | |||
$dependencies->addClassDependency(Validation::class, 'symfony/validator'); | |||
$dependencies->addClassDependency(SecurityBundle::class, 'security-bundle'); | |||
$dependencies->addClassDependency(AppVariable::class, 'twig'); | |||
$dependencies->addClassDependency(TranslatorInterface::class, 'symfony/translation', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add this here? I believe the end result is if you are missing any required dependencies, then the composer require
will now include symfony/translation
in the error message. But, the user doesn't NEED to install this package, and I think the intention is just to detect IF they have it, so that we can know how to generate the controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weaverryan The intention is meant to be exactly like you described! If users have a translator installed - they will have translated exceptions. But without this line tests were failing somehow... and I passed false
as the 3rd argument there that already says this dependency is "optional" and not "required". Is it enough? Or do I understand that 3rd option wrong and it's not about specifying required/optional dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, if it was to get the tests working, then try adding ->addExtraDependencies()
in the test case - e.g.
->addExtraDependencies('api') |
Normally, when you run a test, it will find all of the dependencies configured in this method and will install those. So probably this solution worked because it caused the symfony/translator
to be installed. BUT, we don't really want to recommend it as a package, so probably the better thing to do is to not include it here, but then hint to the test system that it SHOULD install it.
However, if you didn't include it here AND you didn't include it in setExtraDependencies()
, in theory, the tests should NOT have failed. In that situation, the test would have been testing the "what happens of symfony/translator
is not installed situation". We may need to have one test that does NOT include symfony/translator
and another that DOES include it, and we make sure both work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrushlow Thanks for the tip! Hm, I tried to replace PHP_EOL with "\n" to see if tests will pass. But without that new line char at the end the line pops up to the previous in the rendered HTML, i.e. something like: if ($form->isSubmitted() && $form->isValid()) {
return $this->processSendingPasswordResetEmail(
$form->get('email')->getData(),
$mailer, $translator );
} Let's see if "\n" helps |
Tests are green! Though this question is still open probably: #1059 (comment) |
|
||
$this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']); | ||
|
||
$this->runResetPasswordTest($runner, 'it_generates_with_normal_setup.php'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it's OK to reuse this it_generates_with_normal_setup.php
here because I literally just copy/pasted the it_generates_with_normal_setup
test completely where just added addExtraDependencies('symfony/translation')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could remove all the assertions inside of run()
except for $this->assertStringContainsString('Success', $output);
and $this->runResetPasswordTest($runner, 'it_generates_with_normal_setup.php');
. So, just make it a simpler "smoke test" since the earlier test already covers all the details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
8ad30eb
to
b771178
Compare
Thank you Victor! |
This PR was merged into the 1.0-dev branch. Discussion ---------- [release] prep v1.37.0 # RELEASE Hi Makers! This release handles several bug fixes within MakerBundle and adds support for translating ResetPasswordBundle Exception messages, using constants instead of strings with `make:voter`, improved types for `Collection` getter methods in Entities, and support for attributes in `make:registration`! Diff: v1.36.4...v1.37.0 Happy making! --- # CHANGELOG ## [v1.37.0](https://github.com/symfony/maker-bundle/releases/tag/v1.37.0) *February 15th, 2022* ### Feature - [#1062](#1062) - [MakeRegistration] add support for verify email attributes - *`@jrushlow`* - [#1059](#1059) - [make:reset-password] Translate exception reasons provided by ResetPasswordBundle - *`@bocharsky`-bw* - [#1057](#1057) - [Voter] Refactor attributes - *`@mdoutreluingne`* - [#1040](#1040) - [make:entity] Chaing getter PHPDoc return type on Collection - *`@mehdibo`* ### Bug Fix - [#1060](#1060) - Add missing Passport use statement - *`@bocharsky`-bw* - [#1032](#1032) - [reset-password] Coding standards - Twig - *`@seb`-jean* - [#1031](#1031) - [verify-email] Coding standards - Twig - *`@seb`-jean* - [#1027](#1027) - Fixing wrong messaging in make:auth about checking password in final steps - *`@weaverryan`* - [#985](#985) - [make:auth] fix security controller attributes - *`@jrushlow`* Commits ------- 52063a9 [release] prep v1.37.0
If there's
Symfony\Contracts\Translation\TranslatorInterface
service available in the project - Maker will generate a slightly different controller's code to inject translator service and translate exception reasons out of the box.Available after: SymfonyCasts/reset-password-bundle#206