-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added note about using the Validator TypeTestCase in form unit testing #7587
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
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.
Thanks!
Actually, after thinking about this again I am 👎 on merging the PR as is. We usually don't want to guarantee BC for classes that live inside the |
What would you suggest needs to change? Should the class be moved to the |
I am not completely settled on that yet. The main issue is: What if you need another extension? Which base class do you extended then (supposed there is a base class for the other extension as well)? |
I think the best is to open an issue on the code repository and discuss the matter over there first. |
While I like your suggestion, I don't think we should document classes that live in Instead, we should update our example to fix the code. This probably means finishing #6463 . However, if it turns out to be a very nice addition to unit testing, the class might need to be moved to |
Hence my original PR that added the validator to the main base class with an extension point to register custom extensions (and other core extensions can be added in the same place). |
Sorry if I duplicated something that's already done. I lost overview with all these referenced PRs. 😇 |
I would suggest updating the standard base class to include the validator extension, and remove (deprecate?) the one under |
I don't think this will be accepted by the core team. The form component can be used standalone without the validator, so it should at least be optional. You may create a trait with a |
This should cover the case where the form component is used in standalone mode and the validator is not installed. |
form/unit_testing.rst
Outdated
@@ -157,40 +157,49 @@ before creating the parent form using the ``PreloadedExtension`` class:: | |||
be getting errors that are not related to the form you are currently | |||
testing but to its children. | |||
|
|||
Forms Using Validation |
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.
@pierredup Can you remove this section? We can then still merge your fixes to the class namespaces which is still a legit fix.
66a009b
to
6fda2df
Compare
form/unit_testing.rst
Outdated
return array( | ||
new ValidatorExtension($validator), |
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.
Should these changes also be reverted?
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 so
…to base TypeTestCase (pierredup) This PR was squashed before being merged into the 3.4 branch (closes #21960). Discussion ---------- Remove Validator\TypeTestCase and add validator logic to base TypeTestCase | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no/possibly | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | symfony/symfony-docs#7587 Based on a discussion in the docs, users should not really extend classes in the `Tests` namespace. This means that if you want to unit test forms, you need to extend the `Test\TypeTestCase` class which doesn't have the validation logic (Not adding the validator extension gives an error if you use the `constraints` option in your forms). So I propose to remove the `Validator\TypeTestCase` class (or it can possibly be deprecated if it is wrongly used by someone), and add the validator extension logic to the base `TypTestCase` class. The benefit is that there is only one class to extend (both for internal or userland tests), and it makes it easy to add more core extensions if necessary. The one part that I don't like too much at the moment, is keeping the extension in the `getExtensions` method. This means that you extend the class and need to register custom extensions, that you would need to do `return array_merge(parent::getExtensions(), ... ` (only in the case when you want core extensions enabled). So I don't know if we rather want to add a private method like `getCoreExtensions`? Commits ------- 5ab5010 Remove Validator\TypeTestCase and add validator logic to base TypeTestCase
What can we do to make this PR mergeable? Thanks! |
@javiereguiluz Revert everything excepted namespaces modifications like https://github.com/symfony/symfony-docs/pull/7587/files#diff-d9a34263773b4fe7719e18118a10e628R204. |
@pierredup we had to revert part of your proposed changes, but merged others. Thanks for your contribution! |
… unit testing (pierredup, javiereguiluz) This PR was merged into the 2.7 branch. Discussion ---------- Added note about using the Validator TypeTestCase in form unit testing This update ads the usage of the validator TypeTestCase class to use for testing when validation is required. Commits ------- c495b92 Readded a blank line ff1bd8e Reverted some changes f0887ae Remove section about forms using validation 6fda2df Removed extra class cf0f9e6 Update fomr testing sentence 070b2c0 Renamed TestedTypeTests to TestedTypeTest d17821a Fix heading underlining d4979eb Fix typos 3e6dc19 Add docs about the validator TypeTestCase class
This update ads the usage of the validator TypeTestCase class to use for testing when validation is required.