Make WordPress Core

Opened 6 months ago

Closed 4 weeks ago

#62278 closed task (blessed) (fixed)

Tests: Reduce usage of assertEquals for 6.8

Reported by: desrosj's profile desrosj Owned by:
Milestone: 6.8 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 (11)

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


6 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.

Trac ticket: https://core.trac.wordpress.org/ticket/62278

#2 @desrosj
6 months ago

  • Type changed from defect (bug) to task (blessed)

#3 @SergeyBiryukov
4 months ago

In 59516:

Tests: Clean up convert_smilies() tests.

Includes:

  • Removing redundant use_smilies option switches, as it is set to 1 by default.
  • Restoring the $wpsmiliestrans array before performing assertions, not after.
  • Moving most of the smilies_init() calls to a set_up() method.

Follow-up to [409/tests], [26191], [28717].

See #62278.

#4 @SergeyBiryukov
5 weeks ago

In 59985:

Tests: Use assertSame() in some newly introduced 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 [59630].

See #62278.

#5 @SergeyBiryukov
4 weeks ago

In 60067:

Tests: Use assertSame() in REST API schema sanitization 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 [39061], [48937].

See #62278.

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


4 weeks ago
#6

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/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

#7 @SergeyBiryukov
4 weeks ago

In 60068:

Tests: Use assertSame() in REST API attachments 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 [48291], [50124], [57603].

See #62278.

#8 @desrosj
4 weeks ago

I've created #63169 for the 6.9 cycle.

#9 follow-up: @desrosj
4 weeks ago

@SergeyBiryukov are there any more updates that you have planned here for 6.8?

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


4 weeks ago

#11 in reply to: ↑ 9 @SergeyBiryukov
4 weeks ago

  • Resolution set to fixed
  • Status changed from new to closed

Replying to desrosj:

are there any more updates that you have planned here for 6.8?

No, closing as fixed for this cycle :)

Note: See TracTickets for help on using tickets.