Problem/Motivation
UnitTestCase::assertArrayEquals seems redundant now - PHPUnit's provided assertEquals method is actually doing a per-key comparison in associative arrays by default; in case the structure matters assertSame can do, and in case of simple arrays assertEqualsCanonicalizing can be used to pre-sort values before comparison.
Proposed resolution
Deprecate assertArrayEquals and replace its usages with standard PHPUnit methods.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | 3135027-38.patch | 27.56 KB | ayushmishra206 |
| #38 | interdiff_36-38.txt | 2.12 KB | ayushmishra206 |
| #36 | 3135027-36.patch | 27.55 KB | ayushmishra206 |
| #36 | interdiff_30-36.txt | 2.06 KB | ayushmishra206 |
| #34 | 3135027-34.patch | 27.54 KB | ayushmishra206 |
Comments
Comment #2
mondrakeComment #3
mondrakeComment #4
mondrakeComment #6
mondrakeFixed error in #3, more cleanup
Comment #7
kristen polThanks for the patch.
1) Patch applies cleanly to 9.1 and deprecation starts with that version so I didn't try it on previous versions.
2) Searched for
assertArrayEqualsafter applying the patch and only found the code that was added in the patch.3) Reviewed the changes:
a) Most of the changes were
assertArrayEqualstoassertEqualsso I checked the parameters didn't change for those.b) A few (below) were
assertArrayEqualstoassertEmptyandassertArrayEqualstoassertSame. I wasn't sure whyassertEmptywas used in one case whereasassertSamefor the rest.Is this correct? Not mentioned in recommendations.
c) Reviewed wording of messages.
This is following a typical pattern. Side note, some use
in drupal:10.0.0and somefrom drupal:10.0.0but it's pretty even:Nitpick: Add Oxford comma after
::assertEqualsCanonicalizing.Needs change record so tagging this. Obviously, this will need updating afterwards. :)
Follows a typical pattern. I saw some messages with
()after__METHOD__, e.g.but I don't think that needs to be added.
Nitpick: Add Oxford comma after
::assertEqualsCanonicalizing.Follows a typical pattern.
Nitpick: Add Oxford comma after
::assertEqualsCanonicalizing.4) Moving back to "Needs work" to possibly address items in 3) and to create change record and then update the patch with the change record node id.
Comment #8
mondrakeon this
Comment #9
mondrakeThanks for your review.
Added CR.
7.1. this is backportable to earlier branches if deemed relevant, once the deprecation code is removed.
7.3.b. changed to assertEmpty - here it could be questionable one way or another, because empty does not mean the variable under test is an array. But that does not seem the relevant part of the assertions here.
7.3.c.1 AFAICS the policy now is final and requires using 'removed in drupal:x.x.x'
Comment #10
kristen polThanks for the update.
1) Reviewed the change record at:
https://www.drupal.org/node/3136304
and it seems clear enough to me although I wonder if
assertEmptyshould be included in the list given that it's been used to replace an number of asserts in this issue, or maybe that would be confusing without an example.2) Reviewed the interdiff:
a) Regarding
assertEmptyvsassertSame:I like the simplicity of
assertEmptyvsassertSamebut I was wondering if the point of the tests was to ensure the value was an empty array and not just any empty value. From your comment, it seems the ones you changed don't need to check it's an array. The first change you did does check it's an empty array in two steps with theassertIsArrayand then theassertEmpty. If we needed two calls for each check, then I'd prefer to go back to usingassertSamewith the empty array ([]) instead so it's all handled in one check. But, this approach is clear and I don't have a strong opinion.b) See the change record node id was added in place of the
TODOs.c) See the Oxford commas were added.
3) Reviewed the patch again:
a) I see a couple
assertSamechecks remain which might be fine per discussion above.b) I have the same thought from above about adding
assertEmptyto the lists here but, without an example, it may be confusing.4) Patch applies cleanly to 9.1.
5) Test are still running.
6) In order for me to feel comfortable marking RTBC, I'd like to review the
assertEmptyvsassertSameusage and see if the test needs to check if it's an empty array or just an empty value. Unfortunately, I'm not sure I can do that today.Comment #11
nitesh624Comment #12
nitesh624As oer the comment on #10 updated the below lines
Comment #13
kristen pol@nitesh624 When you add updated patches, it's very helpful if you would add a comment why you are making changes. The interdiff is very useful but understanding the motivation for the update is important. Thanks.
Comment #14
nitesh624Comment #16
rajandro commentedWorking on it.
Comment #17
rajandro commentedI have checked the above patch locally and it's not showing any error for the first two cases, let me re-add a test to verify with the current core version what else we need to fix.
Adding the screenshot of the test output for reference.
Thanks
Rajandro
Comment #18
rajandro commentedAdding the updated patch with the test case failure fixing.
PS: Since this fix is a change in the Trait, so if this is not required or out of scope, then we can revert the changes. Please review it.
Thanks
Rajandro
Comment #19
rajandro commentedComment #20
mondrakeComment #22
spokjeComment #23
spokjeNew usages of
assertArrayEqualswere introduced since the latest patch #18.Comment #24
spokjeComment #25
longwaveThe method names should end with
()to make it clearer.Comment #26
spokjeAddressed #25
Comment #27
longwaveThanks, looks good to me.
Comment #28
catchWhy assertSame() for one empty comparison then assertEmpty() for the next.
Also we don't need the array_keys() for these since an empty array has no keys.
Comment #29
spokjeComment #30
spokjeAddressed #28
Comment #31
mondrakeI think here (and in other parts of the patch) we're losing checking the value returned is an array.
So either
$this->assertSame([], ...);or
Comment #32
catchI'd probably go for:
$this->assertSame([], ...);Comment #33
ayushmishra206 commentedWorking on changes suggested in #31
Comment #34
ayushmishra206 commentedMade the changes, please review.
Comment #35
mondrakeAll those in the interdiff in #30 need to be addressed.
Comment #36
ayushmishra206 commentedPlease review.
Comment #37
mondrakeSince we're at this, let's convert these also to
$this->assertSame([], ...);.Comment #38
ayushmishra206 commentedMade the changes suggested in #37.
Comment #39
mondrakeLooks good now, all comments addressed. Thanks.
Comment #41
catchCommitted 47355e3 and pushed to 9.1.x. Thanks!
Comment #42
mondrakePublished CR