[wp-trac] [WordPress Trac] #38266: Tests: Use assertSame() when the type of the value in the assertion is important

WordPress Trac noreply at wordpress.org
Sun Sep 6 23:53:11 UTC 2020


#38266: Tests: Use assertSame() when the type of the value in the assertion is
important
-----------------------------------+-----------------------------
 Reporter:  johnbillion            |       Owner:  SergeyBiryukov
     Type:  defect (bug)           |      Status:  accepted
 Priority:  normal                 |   Milestone:  5.6
Component:  Build/Test Tools       |     Version:
 Severity:  normal                 |  Resolution:
 Keywords:  needs-unit-tests php8  |     Focuses:
-----------------------------------+-----------------------------

Comment (by SergeyBiryukov):

 The commits here so far have reduced the number of `assertEquals()`
 instances from 8378 matches in 431 files (WordPress 5.5) to 572 matches in
 121 files.

 The remaining instances fall into three groups:

 * Ones that use delta comparison for floats, dates, etc. These should be
 switched to [https://github.com/ory/oathkeeper-client-
 php/blob/master/vendor/phpunit/phpunit/ChangeLog-7.5.md#added
 assertEqualsWithDelta()] once PHPUnit 7.5 is the minimum supported
 version.
 * Ones that legitimately use `assertEquals()` for comparing objects.
 Trying to switch these to `assertSame()` would result in "Failed asserting
 that two variables reference the same object" error.
 * Ones that should be switched to `assertSame()`, but would currently
 result in a failure when doing so, due to data type mismatches, mostly
 strings vs. integers, or integers vs. floats. These need further
 investigation:
  * In some cases, the tests should be adjusted to use the correct data
 type.
  * In other cases, this points to minor bugs in core, e.g. using `ceil()`
 for values that are documented as integers, but without explicitly casting
 to `int`, results in them being of type `float` instead. This affects some
 properties like `max_num_pages`, `max_pages`, `total_pages` in various
 classes, or functions like `get_comment_pages_count()`,
 `wp_embed_defaults()`, `get_oembed_response_data()`.

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


More information about the wp-trac mailing list