[wp-trac] [WordPress Trac] #55918: Call wpTearDownAfterClass() before deleting all data, instead of after
WordPress Trac
noreply at wordpress.org
Tue Sep 20 23:52:05 UTC 2022
#55918: Call wpTearDownAfterClass() before deleting all data, instead of after
--------------------------------------+---------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.1
Component: Build/Test Tools | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+---------------------
Comment (by SergeyBiryukov):
Replying to [comment:7 ironprogrammer]:
> Due to
[https://wordpress.slack.com/archives/C03B0H5J0/p1661878866652479?thread_ts=1661878420.775379&cid=C03B0H5J0
lingering questions] related to the continued use of
`wpSetUpBeforeClass()` / `wpTearDownAfterClass()`, versus
[https://make.wordpress.org/core/handbook/testing/automated-testing
/writing-phpunit-tests/#shared-fixtures recent Core Handbook guidance to
favor the newer] `set_up_before_class()` / `tear_down_after_class()`
methods, I propose punting this for further exploration and consensus.
Hmm, there might be some confusion here. As previously noted in
[https://github.com/WordPress/wordpress-
develop/pull/3051#discussion_r952753114 this comment], that handbook
paragraph specifically applies to the native PHPUnit methods that need to
be replaced with WordPress' `snake_case` counterparts, as the tests would
not pass across all supported PHP and PHPUnit versions otherwise:
* `setUpBeforeClass()` → `set_up_before_class()`
* `tearDownAfterClass()` → `tear_down_after_class()`
It does not apply to WordPress' own methods (note the `wp` prefix):
* `wpSetUpBeforeClass()`
* `wpTearDownAfterClass()`
These are fine to use and are used in many other tests, much more often
than the previous methods. That is the reason I'd like to standardize on
these across the test suite for consistency, since they are already used
in the majority of tests.
Happy to do it the other way around and standardize on
`set_up_before_class()` / `tear_down_after_class()` if that's preferred.
Either way, the bug should be fixed for `wpTearDownAfterClass()` and
`tear_down_after_class()` to have access to the same data and to become
interchangeable. As mentioned in the ticket description, the
standardization can be a potential future enhancement and does not have to
be in the scope of this ticket.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55918#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list