[8.x] Add a phpunit comparator for models #38393
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a phpunit comparator for models.
The comparator compares the models based on the model
ismethod.Phpunit comparators are used for the methods
assertEqualsandassertNotEquals.I often encounter that I want to check if two models are the same, and then use the
assertEquals, only to get an error about things not being identical. This is often caused by fields like thewasRecentlyCreatedand so on.To get around this I normally write
assertTrue($model->is($otherModel)).This solution might be BC and should have been submitted to L9, as it changes the current
assertEqualsresult, however submitting it to L8 because it uses the officialismethod which is used for comparing models. If you consider this a BC i'll submit to L9 instead 👍Another solution for this would be so instead of using the
ismethod for comparison it uses thegetAttributesarrays for comparison.