[wp-trac] [WordPress Trac] #52482: Tests: Reduce usage of assertEquals() for 5.8

WordPress Trac noreply at wordpress.org
Wed Feb 10 07:50:11 UTC 2021


#52482: Tests: Reduce usage of assertEquals() for 5.8
-----------------------------------+---------------------
 Reporter:  johnbillion            |       Owner:  (none)
     Type:  task (blessed)         |      Status:  new
 Priority:  normal                 |   Milestone:  5.8
Component:  Build/Test Tools       |     Version:
 Severity:  normal                 |  Resolution:
 Keywords:  needs-unit-tests php8  |     Focuses:
-----------------------------------+---------------------

Comment (by SergeyBiryukov):

 If we ignore `assertEqualsWithDelta()` and search specifically for
 `assertEquals()`, there are currently 653 matches in 128 files. This has
 gone up a bit since WordPress 5.6: comment:19:ticket:38266 (572 matches in
 121 files), so apparently some newly introduced tests use `assertEquals()`
 instead of `assertSame()`. Some of those were corrected in [49126] and
 [49547], but more were added in 5.7.

 Would it be appropriate to add an automated check for this, or at least
 recommend using `assertSame()` in the core contributor handbook? I've
 updated the examples in [https://make.wordpress.org/core/handbook/testing
 /automated-testing/writing-phpunit-tests/ Writing PHPUnit Tests] to use
 `assertSame()`, but perhaps we could also be explicitly state somewhere
 that it should be preferred to `assertEquals()` where possible.

 Replying to [comment:3 jrf]:
 > One note about this: when comparing whether two objects of the same type
 are "equal", using `assertEquals()` is still warranted. `assertSame()`
 would fail for objects of the same type with the same property values, as
 the ID of the object will, in most cases, not be the same.

 Indeed, also previously noted in comment:19:ticket:38266. Thanks for
 pointing that out!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52482#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list