Skip to content

[Validator] Deprecated email validation mode loose #43505

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

Closed
wants to merge 34 commits into from

Conversation

ThomasLandauer
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? yes
Tickets Fix #41855
License MIT
Doc PR TODO

Closes #41855

Don't know what else needs to be done... ;-)

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@ThomasLandauer ThomasLandauer marked this pull request as ready for review October 14, 2021 12:07
@carsonbot carsonbot added this to the 5.4 milestone Oct 14, 2021
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

a similar notice is needed in validate(), isn't it?

@ThomasLandauer
Copy link
Contributor Author

Should I commit the actual removal of "loose" to the 6.0 branch already, or when is the "usual" time to do this?

@nicolas-grekas nicolas-grekas changed the title Deprecating "loose" mode Deprecated email validation mode loose Oct 27, 2021
@carsonbot carsonbot changed the title Deprecated email validation mode loose [Validator] Deprecated email validation mode loose Oct 27, 2021
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

the constraint should also trigger a deprecation when you instantiate it with a config putting it in loose mode

Not sure this is required to me. Not doing that would prevent triggering two very similar deprecations instead, thus reducing confusion.

@xabbuh
Copy link
Member

xabbuh commented Oct 28, 2021

So am I right that (at least as a first step) those 98 "self deprecation notices" need to get fixed? But how?

You need to update these tests to use the html5 mode instead of the implicit loose default mode.

@stof
Copy link
Member

stof commented Oct 28, 2021

So from what you said above ("and probably also assert that they expect the deprecation") I figured I had to add $this->expectDeprecation();. But the result is:

There was 1 failure:

  1. Symfony\Component\Validator\Tests\Constraints\EmailValidatorTest::testModeLoose
    Failed asserting that exception of type "PHPUnit\Framework\Error\Deprecated" is thrown.

So am I right that (at least as a first step) those 98 "self deprecation notices" need to get fixed? But how?

you need to use the ExpectDeprecationTrait from the PHPUnit bridge, not the API defined in PHPUnit 8+ (which does not work for our silenced deprecations)

@ThomasLandauer
Copy link
Contributor Author

At least I managed to get rid of the 4 coming from ValidationTest.php. But I'm stuck with the 94 from EmailValidatorTest.php :-(

94x in EmailValidatorTest::setUp from Symfony\Component\Validator\Tests\Constraints

Don't even know what setUp refers to - there is no such method in that file.

@@ -21,6 +22,8 @@
*/
class EmailValidatorTest extends ConstraintValidatorTestCase
{
use ExpectDeprecationTrait;

protected function createValidator()
{
return new EmailValidator(Email::VALIDATION_MODE_LOOSE);
Copy link
Member

Choose a reason for hiding this comment

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

The createValidator() method is called in setUp() in the base ConstraintValidatorTestCase class. That call will lead to the deprecation being triggered here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I need to add @group legacy and $this->expectDeprecation at ConstraintValidatorTestCase::setUp?

Cause I'm sure I already tried it here at EmailValidatorTest::createValidator() and it didn't work...

Copy link
Member

Choose a reason for hiding this comment

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

No, you need to update this method to not pass loose but html5 as the mode instead. The legacy loose mode needs to be tested explicitly in legacy test methods instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think since we changed this, the deprecation warning is gone:

1) Symfony\Component\Validator\Tests\Constraints\EmailValidatorTest::testValidEmailsLoose with data set #0 ('fabien@symfony.com')
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
 @expectedDeprecation:
-%A  Since symfony/validator 5.4: The "loose" email validation mode is deprecated, use "html5" instead
+

So do I need to trigger_deprecation() in createValidator() too? But wouldn't this result in what @nicolas-grekas said he doesn't want? #43505 (review)

Not sure this is required to me. Not doing that would prevent triggering two very similar deprecations instead, thus reducing confusion.

@ThomasLandauer
Copy link
Contributor Author

The purpose of EmailValidatorTest::testValidNormalizedEmails() seems to be to test the normalizer. So should I just delete all "html5-failing" email addresses from the data provider?

@fabpot fabpot modified the milestones: 5.4, 6.1 Oct 30, 2021
@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@fabpot
Copy link
Member

fabpot commented Jul 23, 2022

Closing as it has been finished in #46518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Validator] Change default mode of Assert\Email to "strict", for consistency with Mailer
7 participants