Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[serializer] extract normalizer tests to traits#30888

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromdbu:refactor-normalizer-tests
Apr 27, 2019

Conversation

@dbu
Copy link
Contributor

@dbudbu commentedApr 6, 2019
edited
Loading

eufossa

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsRelates to#30818
LicenseMIT
Doc PR-

As discussed with@joelwurtz, extract normalizer functionality tests into traits to ensure consistent behaviour of all normalizers.

Stuff that we should do eventually, but can also do in separate pull requests, after this one has been merged:

  • Extract all features that we can (the existing normalizer tests should more or less only have the legacy tests in them, all functionality should be in trait)
  • Run test coverage and increase coverage so that we cover all important features and all relevant error cases.

joelwurtz reacted with thumbs up emojimaxhelias reacted with hooray emoji
@dbudbuforce-pushed therefactor-normalizer-tests branch 5 times, most recently from50d6a38 to37adf7fCompareApril 6, 2019 15:45
@nicolas-grekasnicolas-grekas added this to thenext milestoneApr 6, 2019
@dbudbuforce-pushed therefactor-normalizer-tests branch from1388449 tobc48707CompareApril 7, 2019 08:12
@dbudbuforce-pushed therefactor-normalizer-tests branch fromd1986aa toe5da4cdCompareApril 7, 2019 09:32
@dbudbuforce-pushed therefactor-normalizer-tests branch from97741e2 to526dbdeCompareApril 7, 2019 10:03
Copy link
Member

@dunglasdunglas left a comment

Choose a reason for hiding this comment

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

What a work! This looks very promising.

* You can raise this value for special cases, e.g. in combination with the
* max depth setting of the object normalizer.
*/
publicconstCIRCULAR_REFERENCE_LIMIT ='circular_reference_limit';
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about moving all these constants in the interface, and to add a builder object for better autocompletion in IDEs (exactly as done in HttpClient)?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

i agree that they should be in the interface. otherwise the interface is a lie. and we should define that when an option is not known by the normalizer implementation, it has to throw an exception. otherwise the behaviour is very undefined and e.g. typos are not spotted.

i also think we could use the OptionsResolver on them to validate, instead of the case-by-case validation we do at the moment (see#30907,#30950, its too easy to forget to validate things)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@joelwurtz should we move the constants in this PR? i feel we should probably do that separately, also reviewing if they all stay the same or we want some different options and only keep some for legacy support.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like explained in#30818 we should have a global politic about context and where to put const of this context. I would be in favor of@dunglas proposal in order to be consistent with how others components works.

But it's clearly not in the scope of this PR. And this is something that should be done once we are satisified with the overall implementation. First let's do a good implementation, then we focus on DX for that, WDYT@dunglas ?

Copy link
Member

@dunglasdunglasApr 7, 2019
edited
Loading

Choose a reason for hiding this comment

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

otherwise the behaviour is very undefined and e.g. typos are not spotted

It’s not really doable because most likely the context will be passed to the Serializer instance, that will call many normalizers (another normalizer can be used for relations for instance).

+1 to move these constants in another PR.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

could we then make the serializer validate the context? e.g. by collecting from all its registered normalizers what options they support?

i am just very unhappy with these kind of unvalidated array configuration, as its super hard to debug when you make mistakes.

is the context supposed to also contain custom options for specific normalizers or is it a closed list of features? if it is closed, we could change from array to a value object that does the validation and defines what keys are possible. then we could do the validation once in that object and all normalizers can rely on only getting valid information.

Copy link
Member

Choose a reason for hiding this comment

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

is the context supposed to also contain custom options for specific normalizers or is it a closed list of features?

Yes, it is an extension point for custom normalizers and encoders too. It’s used (and sometimes abused) a lot by API Platform and many other tools using this component.

What we would to is to validate when using the new « context builder » as in HttpClient (when using this builder, we know the list of keys) and don’t validate anything (as currently) in the normalizers.
Another alternative would be to introduce a new parameter for « built-in » options that would be a class, but keep the context as an extension point (I’m less fond of this one because it will make the public API harder to learn).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

could we make the $context into a value object with explicit methods (and validation) for the known options, and a generic getExtra(string $name), setExtra(string $name, mixed $thing) method? this would make a good compromise to solve validation and the typo risk issue while keeping flexibility.

i dislike that every context validates the context parameters again, as they can be called repeatedly.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

this is out of scope for this pull request. i don't have time for another pull request for it, but if somebody wants to do it, please do

@nicolas-grekas
Copy link
Member

Please note that we will ask you to squash the git history of the PR before merging, to keep at most one commit per author.

@joelwurtz
Copy link
Contributor

About squashing, if it's easier for you@dbu i don't mind having my name removed from the commit list

@dbudbuforce-pushed therefactor-normalizer-tests branch from3f46692 tocbbda0bCompareApril 8, 2019 07:35
@dbu
Copy link
ContributorAuthor

dbu commentedApr 8, 2019

i squashed. i don't feel much of an author on those, mostly moved the tests from elsewhere :-D

@dbudbu changed the titleWIP: extract normalizer tests to traitsWIP: [serializer] extract normalizer tests to traitsApr 8, 2019
@fabpot
Copy link
Member

@dbu Is it still WIP?

@dbu
Copy link
ContributorAuthor

dbu commentedApr 8, 2019
edited
Loading

yes, still WIP. i want to go over the changes to streamline them a bit, and i want to wait for the bugfixes#30977,#30950 and#30907 landing in master to rebase and solve the conflicts that will happen.

fabpot added a commit that referenced this pull requestApr 8, 2019
…malizer context (dbu)This PR was merged into the 4.2 branch.Discussion----------[Serializer] Also validate callbacks when given in the normalizer context| Q             | A| ------------- | ---| Branch?       | 4.2 (callbacks are handled differently in 3.4)| Bug fix?      | yes| New feature?  | no| BC breaks?    | no (unless somebody relied on this bug ignoring `null` as callback| Deprecations? | no| Tests pass?   | yes| Fixed tickets | Related to#30888| License       | MIT| Doc PR        | -callbacks configuration for the normalizer is validated to be valid callbacks when using setCallbacks or using the callbacks field in the default options. however, it was not validated when using the callbacks field in a context passed to `normalize()`Commits-------3789152 [serializer] validate that the specified callbacks and max_depth_handler are actually callable
@dbudbuforce-pushed therefactor-normalizer-tests branch 2 times, most recently from73d435f to3dfd83bCompareApril 9, 2019 06:00
@dbudbu changed the titleWIP: [serializer] extract normalizer tests to traits[serializer] extract normalizer tests to traitsApr 11, 2019
@dbudbuforce-pushed therefactor-normalizer-tests branch from4fb71a7 to22c1092CompareApril 11, 2019 05:53
@dbu
Copy link
ContributorAuthor

dbu commentedApr 11, 2019

I now consider this ready for final review /cc@joelwurtz@dunglas

the open points can be done in follow-up pull requests and i don't have any more time to start fresh things (but will of course wrap up if you have feedback on this PR so that we can merge it)

nicolas-grekas added a commit that referenced this pull requestApr 11, 2019
… isAllowedAttribute (dbu)This PR was merged into the 3.4 branch.Discussion----------property normalizer should also pass format and context to isAllowedAttribute| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | found while working on#30888| License       | MIT| Doc PR        | -the context and format are optional parameters to `isAllowedAttribute`, but should be forwarded. due to this omission, the PropertyNormalizer was ignoring the 'attributes' context option (and does in version 4 also ignore the 'ignore_attributes' context option - that one is a property on the normalizer class in version 3 and therefore not ignored here)Commits-------13e2fb7 property normalizer should also pass format and context to isAllowedAttribute
@dbudbuforce-pushed therefactor-normalizer-tests branch from22c1092 toc83ea84CompareApril 26, 2019 11:01
@dbu
Copy link
ContributorAuthor

dbu commentedApr 26, 2019

what do we need to be able to merge this?

@fabpotfabpotforce-pushed therefactor-normalizer-tests branch fromc83ea84 to2b6ebeaCompareApril 27, 2019 16:25
@fabpot
Copy link
Member

Thank you@dbu.

sroze reacted with hooray emoji

@fabpotfabpot merged commit2b6ebea intosymfony:masterApr 27, 2019
fabpot added a commit that referenced this pull requestApr 27, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes#30888).Discussion----------[serializer] extract normalizer tests to traitseufossa| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | Relates to#30818| License       | MIT| Doc PR        | -As discussed with@joelwurtz, extract normalizer functionality tests into traits to ensure consistent behaviour of all normalizers.* [x] Rebase when#30977,#30950 and#30907 are merged to master **blocker*** [x] Clean up order of trait inclusion and methods in the tests* [x] Clean up fixture classes of the traits. I started having one class named the same as the trait, where possibleStuff that we should do eventually, but can also do in separate pull requests, after this one has been merged:* [ ] Extract all features that we can (the existing normalizer tests should more or less only have the legacy tests in them, all functionality should be in trait)* [ ] Run test coverage and increase coverage so that we cover all important features and all relevant error cases.Commits-------2b6ebea [serializer] extract normalizer tests to traits
@chalasrchalasr mentioned this pull requestApr 27, 2019
fabpot added a commit that referenced this pull requestApr 28, 2019
This PR was merged into the 3.4 branch.Discussion----------[Serializer] Fix tests| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | n/a| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | n/a#30888 added some tests on master which fail when `property-info <3.4.13` is installed.This bumps the constraint on 3.4 which will fix the low-deps build once merged up to master.Commits-------d25f650 [Serializer] Fix tests
@joelwurtz
Copy link
Contributor

Thanks you@dbu will update my prs with those test

@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
fabpot added a commit that referenced this pull requestMay 10, 2019
…c (dunglas)This PR was merged into the 4.3 branch.Discussion----------[Serializer] Fix BC break: DEPTH_KEY_PATTERN must be public| Q             | A| ------------- | ---| Branch?       | 4.3 Bug fix?      | yes| New feature?  |no <!-- please update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | n/a| License       | MIT| Doc PR        | n/aFix a BC break introduced by#30888. This constant is used by API Platform.Commits-------1bdf2af [Serializer] Fix BC break: DEPTH_KEY_PATTERN must be public
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dunglasdunglasdunglas left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@joelwurtzjoelwurtzjoelwurtz left review comments

@jewome62jewome62jewome62 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

8 participants

@dbu@nicolas-grekas@joelwurtz@fabpot@dunglas@jewome62@michaelcullum@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp