Make WordPress Core

Opened 20 months ago

Closed 12 months ago

Last modified 2 weeks ago

#63169 closed task (blessed) (fixed)

Tests: Reduce usage of assertEquals for 6.9

Reported by: desrosj Owned by:
Priority: normal Milestone: 6.9
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch has-unit-tests needs-refresh
Cc: Focuses: coding-standards

Description

Follow-up to:

The assertEquals() test method does not check that the types of the expected and actual values match. This can hide subtle bugs especially when the values are falsey.

Tasks:

  • Switch to using assertSame() when the type of the value in the assertion is important
  • Replace overall usage of assertEquals() with type-strict assertion methods, with the aim of potentially removing its usage altogether

To help ease the effort of merging tests, changes should also be made upstream in the Gutenberg repository.

Change History (9)

This ticket was mentioned in ​PR #4132 on ​WordPress/wordpress-develop by ​@Rahmohn.


20 months ago
#1

  • Keywords has-patch has-unit-tests added

This PR updates the test test_wp_count_attachments_should_cache_the_result to check the properties of the object returned instead of checking the object with assertEquals. That way, we guarantee the expected properties of the object.

Track ticket: https://core.trac.wordpress.org/ticket/63169

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


20 months ago

This ticket was mentioned in ​PR #1768 on ​WordPress/wordpress-develop by ​@costdev.


20 months ago
#3

This PR replaces assertEquals() with more appropriate, stricter assertions where possible and without making any changes to source.

For easier reviewing, commits have been separated based on the replacement assertion and any additional changes required to implement the stricter assertion.

Trac ticket: https://core.trac.wordpress.org/ticket/63169
Trac ticket: https://core.trac.wordpress.org/ticket/62278
Trac ticket: https://core.trac.wordpress.org/ticket/61573
Trac ticket: https://core.trac.wordpress.org/ticket/60706
Trac ticket: https://core.trac.wordpress.org/ticket/59655
Trac ticket: https://core.trac.wordpress.org/ticket/55654
Trac ticket: https://core.trac.wordpress.org/ticket/54726
Track ticket: https://core.trac.wordpress.org/ticket/63169

This ticket was mentioned in ​Slack in #core by wildworks. ​View the logs.


13 months ago

#5 @wildworks
13 months ago

  • Keywords needs-refresh added

This ticket was brought up in today's 6.9 bug scrub. To move this issue forward, the PR needs to be refreshed.

#6 @wildworks
13 months ago

  • Milestone 6.9 → 7.0

Since RC1 is approaching and the pull request is outdated, I'm punting this ticket to 7.0. We may be able to close this ticket once a new ticket for 7.0 has been submitted.

#7 @johnbillion
12 months ago

  • Milestone 7.0 → 6.9
  • Resolution → fixed
  • Status new → closed

​@lancewillett commented on ​PR #1768:


2 months ago
#8

Closing as stale. The linked ticket, #63169, was closed for 6.9. The work to reduce assertEquals() usage in 7.2 is tracked on #64895, which has its own PRs. Thanks for starting this, @costdev.

​@lancewillett commented on ​PR #4132:


2 weeks ago
#9

Thanks for this, @Rahmon. Trunk settled this question in https://core.trac.wordpress.org/changeset/64826: test_wp_count_attachments_should_cache_the_result() keeps assertEquals(), with a comment that the objects are compared by value on purpose. Checking two properties would also miss changes to the others, as jrfnl noted, so I'm closing this as superseded.

Note: See TracTickets for help on using tickets.