[wp-trac] [WordPress Trac] #53911: Test modernization backwards-compatibility backports to help security test backports and extenders with WordPress cross-version testing

WordPress Trac noreply at wordpress.org
Fri Sep 24 14:39:24 UTC 2021


#53911: Test modernization backwards-compatibility backports to help security test
backports and extenders with WordPress cross-version testing
--------------------------------------+-----------------------------
 Reporter:  hellofromTonya            |       Owner:  hellofromTonya
     Type:  task (blessed)            |      Status:  reviewing
 Priority:  normal                    |   Milestone:  5.9
Component:  Build/Test Tools          |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------

Comment (by hellofromTonya):

 In [changeset:"51867" 51867]:
 {{{
 #!CommitTicketReference repository="" revision="51867"
 Build/Test Tools: Fix test forward-compatibility layer.

 In [51846], the test wrapper methods were not being called due to the
 names not being recognized as supported PHPUnit "hook" names for fixtures.

 This commit:
 - Fixes the problem by adding extra camelCase wrappers to the
 `WP_UnitTestCase` to call the methods in the right order.
 - Adds wrappers for the `assertPreConditions()` and
 `assertPostConditions()` fixture methods to make the backport feature
 complete for the fixture wrappers.

 Test wrapper methods call fix:

 By adding method overloads for the PHPUnit native camelCase fixture
 methods and letting those call the (camelCase) parent method first and
 only calling the snake_case fixture methods after, the snake_case methods
 can be supported and the typical run order safeguarded.

 As not all test classes will have declared snake_case fixture methods, the
 snake_case fixture methods are also declared in the `WP_UnitTestCase`.
 Why? This prevents having to wrap these method calls in `method_exists()`
 conditions checking for the existence of the snake_case methods in an
 unknown Test child class. And with the normal inheritance rules in
 combination with calling the method using `static`, the right method will
 be called anyway without fatal "calling undeclared method" errors.

 Note: While it will be rare, there ''may'' be cases where a test class
 does not adhere to the normal execution order for fixtures, i.e. for the
 setup methods, parent first, own code second; and for the teardown
 methods, own code first, parent second. For example a test class which has
 "some code - `parent::setUp()` call - some more code" in their `setUp()`
 method. In those (rare) cases, the execution order of the code will now be
 changed, which may have side-effects. This rare case will be identified in
 the dev note.

 Follow-up to [51846], [51847].

 Props bjorsch, swissspidy, jrf, hellofromTonya.
 See #53911.
 }}}

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


More information about the wp-trac mailing list