Opened 2 years ago
Last modified 3 weeks ago
#56740 new enhancement
set_up_before_class() / wpSetUpBeforeClass() are inconsistent and confusing
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Build/Test Tools | Keywords: | |
Focuses: | Cc: |
Description
There was some discussion in #55918 about standardizing on either set_up_before_class()
/set_up_after_class()
or wpSetUpBeforeClass()
/wpSetUpAfterClass()
. That would bring consistency, and help reduce the confusion that exists around those functions. That applies to the tear down functions as well.
See comment:7:ticket:55918 (and replies to it)
See https://wordpress.slack.com/archives/C03B0H5J0/p1660782746785649
See https://wordpress.slack.com/archives/C03B0H5J0/p1661876947032299
The wp...
variants were introduced in r35186.
If a change is made here (and probably even if one isn't), it'd be good to update the handbook page to explain which functions folks should use, and any caveats.
Some context from #55918:
wpSetUpBeforeClass()
/wpTearDownAfterClass()
should not be confused with 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()
(native PHPUnit method) →set_up_before_class()
(WP method)tearDownAfterClass()
(native PHPUnit method) →tear_down_after_class()
(WP method)wpSetUpBeforeClass()
/wpTearDownAfterClass()
are used much more often in the test suite, though it should be possible to standardize onset_up_before_class()
/tear_down_after_class()
instead if that's preferred.set_up_before_class()
/tear_down_after_class()
:wpSetUpBeforeClass()
receives the$factory
argument for ease of use.wpSetUpBeforeClass()
andwpTearDownAfterClass()
don't need to callself::commit_transaction()
.wpSetUpBeforeClass()
/wpTearDownAfterClass()
are used when the$factory
argument is utilized.set_up_before_class()
/tear_down_after_class()
are used when the$factory
argument is not needed, for example to include some files.