WordPress.org

Make WordPress Core

#51344 closed task (blessed) (fixed)

Unit test improvements for 5.6

Reported by: SergeyBiryukov Owned by:
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Background: #38266, #50913.

This ticket is for various fixes and improvements in PHPUnit tests that don't have a more specific ticket.

Change History (25)

#1 @SergeyBiryukov
12 months ago

In 48996:

Tests: Consistently use the expectException() method instead of the older @expectedException annotation.

See https://thephp.cc/news/2016/02/questioning-phpunit-best-practices

The method is available since PHPUnit 5.2, and WordPress currently supports PHPUnit 5.4 as the minimum version.

Follow-up to [48993].

See #51344.

#2 @SergeyBiryukov
12 months ago

In 48997:

Tests: Switch Ajax tests to use the expectException() method directly, instead of the WP_UnitTestCase_Base::setExpectedException() wrapper.

This brings some consistency with other tests.

Follow-up to [48996].

See #51344.

#3 @SergeyBiryukov
12 months ago

In 48998:

Docs: Update the code example in WP_Ajax_UnitTestCase::dieHandler() DocBlock to use expectException().

Follow-up to [48996], [48997].

See #51344.

#4 @SergeyBiryukov
12 months ago

In 48999:

Tests: Simplify PluralFormsTest::test_exceptions().

Previously, the test had to use an older pattern for catching the generic Exception exceptions for compatibility with PHPUnit 3.6 on PHP 5.2.

Now that WordPress supports PHPUnit 5.4 as the minimum version, the expectException() method can be used directly.

Follow-up to [41725], [41730].

See #51344.

#5 @SergeyBiryukov
12 months ago

In 49001:

Tests: Simplify the logic in WP_UnitTestCase_Base::setUpBeforeClass() and ::tearDownAfterClass().

See #51344.

#6 @SergeyBiryukov
12 months ago

In 49003:

Tests: Speed up slashed data tests by reusing shared fixtures.

Follow-up to [35249].

See #51344.

#7 @SergeyBiryukov
12 months ago

In 49004:

Coding Standards: Give the $id variable in slashed data tests a more descriptive name.

See #50767, #51344.

#8 @SergeyBiryukov
12 months ago

In 49005:

Tests: Speed up slashed data tests by reusing some more shared fixtures.

Follow-up to [35249], [49003].

See #51344.

#9 @SergeyBiryukov
12 months ago

In 49027:

Tests: Use consistent trailing punctuation in markTestSkipped() messages.

See #51344.

#10 @SergeyBiryukov
12 months ago

In 49030:

Tests: Fix typo in some markTestSkipped() messages.

See #51344.

#11 @SergeyBiryukov
12 months ago

In 49033:

Tests: Use consistent trailing punctuation in fail() messages.

See #51344.

#12 @SergeyBiryukov
12 months ago

In 49112:

Tests: Use consistent wording for the $position parameter in add_submenu_page() tests.

This replaces the instances of $priority with $position, to match the actual parameter name and avoid confusion.

Follow-up to [46197].

See #51344, #39776.

#13 @SergeyBiryukov
12 months ago

In 49140:

Tests: Correct the message in a sitemaps test for getting a URL list for a custom taxonomy that is not publicly queryable.

Follow-up to [48474].

See #51344, #50607.

This ticket was mentioned in PR #643 on WordPress/wordpress-develop by peterwilsoncc.


11 months ago

  • Keywords has-patch has-unit-tests added

#15 @peterwilsoncc
11 months ago

In 49268:

Tests: Use shared fixtures in XML-RPC new comment unit tests.

See #51344.

#16 @SergeyBiryukov
11 months ago

In 49327:

Tests: Rename some files and classes in phpunit/tests/post/ per the naming conventions.

https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780].

See #51344.

#17 @johnbillion
11 months ago

In 49488:

Tests: Remove some useless assertions from the image editor tests.

In each of these instances the variable being tested is a directly instantiated object and can never be a WP_Error, unlike when wp_get_image_editor() is used.

See #51344

#18 @SergeyBiryukov
11 months ago

In 49543:

Tests: Remove empty export directory.

Follow-up to [30518], [31253], [34328].

See #51344.

#19 @desrosj
11 months ago

In 49554:

Tests: Remove duplicate fields key in WP_Query test.

Introduced in [46188].

See #51344.

#20 @johnbillion
11 months ago

In 49601:

Build/Test Tools: Improve the reliability of the test that ensures correct dependency order when inline scripts are used.

This test already ensures WP_Scripts->do_concat is true, therefore it has no dependency on SCRIPT_DEBUG being false. This means the test can run in an environment where the .min suffix is not used.

This change allows for the test to pass in this situation.

See #36392, #51734, #51344

#21 @johnbillion
10 months ago

In 49603:

Build/Test Tools: Standardise the name, signature, and usage of the wpSetUpBeforeClass() method that's used in test classes.

This brings consistency to this often-used method, and allows IDEs to provide help to developers when using its $factory parameter.

See #51344

#22 @johnbillion
10 months ago

In 49604:

Build/Test Tools: Ensure user capability assertions are performed for all default roles.

The existing assertions were erroneously placed outside the iteration of all users, and therefore were only run against the last user in the list, which is the Subscriber role.

See #51344, #32394

#23 @johnbillion
10 months ago

In 49605:

Built/Test Tools: Switch to a data provider for the default user role and capability tests.

This test previously performed 1,010 assertions, and a failure in any one would prevent the other assertions from running. Using a data provider means simultaneous failures will all be reported at once.

See #51344, #32394

#24 @johnbillion
10 months ago

In 49606:

Build/Test Tools: Misc test enhancements.

See #51344

#25 @SergeyBiryukov
10 months ago

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

Follow-up: #51802

Note: See TracTickets for help on using tickets.