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

Email validator checkMX constraint - disable in test environment #16819

Closed
benr77 opened this issue Dec 3, 2015 · 5 comments
Closed

Email validator checkMX constraint - disable in test environment #16819

benr77 opened this issue Dec 3, 2015 · 5 comments

Comments

@benr77
Copy link
Contributor

benr77 commented Dec 3, 2015

When running test suites, I don't want to rely on an internet connection. However, I have defined the checkMX constraint on various email fields, and this does a remote DNS lookup to perform the validation.

Should it not be possible to tell the validator that for the test environment any remote DNS calls should be skipped? Currently some of my tests fail when there is no connectivity due to the MX lookup failing.

I have tried using expression syntax in the validation but this does not appear to work

email:
      - Email:
          message: The email {{ value }} does not seem to be valid.
          checkMX: @=parameter('kernel.environment') == 'test' ? false : true

Any thoughts?

@linaori
Copy link
Contributor

linaori commented Dec 3, 2015

In my opinion the methods doing these calls should be moved to something that can be injected.

@SoboLAN
Copy link

SoboLAN commented Dec 5, 2015

If I were you, I would:

1). check if the expression above is correct. I'm not very familiar with its syntax, so there could be some small silly mistake that makes it invalid (like maybe it should be enclosed in quotes). The way I would check this is: add a var_dump in EmailValidator::validate() to see the value of that field or where the flow is going. That var_dump will be printed in your stdout while the test is running (console in the case of IDEs).
2). I would rely on kernel.debug instead of kernel.environment, seems clearer and more natural.
3). This is a more ugly solution, but if nothing else works, maybe you could have multiple files with validation constraints and load only one of them based on environment. It duplicates a lot of stuff that way, but at least it's guaranteed to work.
4). From what you say, all this seems like a functional/integration test, which means you probably have easy access to the Container object. If the above suggestions don't work, maybe there's a way of changing that value only for that particular test by using the container.

@benr77
Copy link
Contributor Author

benr77 commented Dec 5, 2015

Thanks @SoboLAN - Yes, it's for functional testing. Personally I don't like polluting the validation.yml with environment specific conditional expressions. Same goes for swapping in a whole new validation.yml file. Kind of ugly fix as you say.

Could the Symfony framework component or the Validator component have some kind of inhibit_external setting that will disable this kind of DNS lookup? It could be integrated in to the test: ~ setting that the framework already has perhaps?

Regarding manipulating this parameter via accessing the container - no idea how to do this if you could provide any pointers to get me started that would be appreciated.

@patrick-mcdougle
Copy link
Contributor

@iltar Where would you recommend a MXChecker as you've proposed move to? It doesn't look like anything else in the validator component does anything like that. I'm on board for the inhibit_external (not convinced on naming) strategy.

@patrick-mcdougle
Copy link
Contributor

This issue will be remedied by #18181 and should be closed when it is merged.

fabpot added a commit that referenced this issue Mar 16, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

[PhpUnitBridge] Mock DNS functions

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16819
| License       | MIT
| Doc PR        | -

Commits
-------

0b31285 [PhpUnitBridge] Mock DNS functions
@fabpot fabpot closed this as completed Mar 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants