Make WordPress Core

Opened 5 months ago

Closed 5 weeks ago

#60706 closed task (blessed) (fixed)

Tests: Reduce usage of assertEquals for 6.6

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by:
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

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 (10)

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


5 months ago
#1

  • Keywords has-patch has-unit-tests added

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/60706
Trac ticket: https://core.trac.wordpress.org/ticket/59655
Trac ticket: https://core.trac.wordpress.org/ticket/55654

#2 @SergeyBiryukov
3 months ago

In 58044:

Tests: Use assertSame() in WP_oEmbed_Controller tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [41047].

Props costdev.
See #60706.

#3 @SergeyBiryukov
3 months ago

In 58052:

Tests: Use assertSame() in wp_handle_comment_submission() tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [38778], [46829].

Props costdev.
See #60706.

#4 @SergeyBiryukov
3 months ago

In 58054:

Tests: Use assertSame() in WP_Comment::get_instance() tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [38381].

Props costdev.
See #60706.

#5 @SergeyBiryukov
3 months ago

In 58070:

Tests: Use assertSame() in wp_validate_redirect() tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [36444].

Props costdev.
See #60706.

#6 @SergeyBiryukov
3 months ago

In 58150:

Tests: Use assertSame() in absint() tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Includes correcting a few erroneously duplicated test cases to match their intended purpose.

Follow-up to [57724].

See #60706.

#7 @SergeyBiryukov
3 months ago

In 58160:

Tests: Use assertSame() in block_has_support() tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [56382].

See #60706.

#8 @SergeyBiryukov
6 weeks ago

In 58478:

Tests: Use assertSame() in WP_Theme_JSON tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [55959], [55986], [57547], [57716], [58244], [58422].

See #60706.

#9 @desrosj
5 weeks ago

  • Keywords close added

@SergeyBiryukov Do you have any further plans for this during 6.6 or can we close and open a new one for 6.7?

#10 @SergeyBiryukov
5 weeks ago

  • Keywords close removed
  • Resolution set to fixed
  • Status changed from new to closed

Closing this one, created #61573 for 6.7.

Note: See TracTickets for help on using tickets.