[wp-trac] [WordPress Trac] #48844: Unit test for wp()
WordPress Trac
noreply at wordpress.org
Sat Feb 8 05:23:02 UTC 2020
#48844: Unit test for wp()
-----------------------------------------+-----------------------------
Reporter: pbearne | Owner: SergeyBiryukov
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 5.4
Component: Bootstrap/Load | Version: trunk
Severity: normal | Resolution:
Keywords: has-unit-tests dev-feedback | Focuses:
-----------------------------------------+-----------------------------
Comment (by SergeyBiryukov):
The last assertion fails because:
1. `wp()` only sets `$wp_the_query` [source:tags/5.3.2/src/wp-
includes/functions.php?marks=1257-1259#L1241 if it's not already set].
2. It is actually already set earlier in [source:tags/5.3.2/src/wp-
settings.php?marks=413#L406 wp-settings.php].
3. It is then reset in [source:tags/5.3.2/tests/phpunit/includes/abstract-
testcase.php?marks=727#L721 WP_UnitTestCase_Base::go_to()], called by
various canonical tests.
4. After that, the variable no longer points to the same object, so
`assertSame()` fails.
Some history on that code:
* [4460] introduced setting `$wp_the_query` in `wp-settings.php`.
* [6233] introduced setting `$wp_the_query` in `wp()`. However, the commit
message on that changeset was wrong, see [6232] / #5121 for the correct
commit message.
Note that `WP::main()` calls `WP::query_posts()`, which produces a fatal
error if `$wp_the_query` is not set by then (`Call to a member function
query() on null`), and did so in WP 2.3.3 too.
Given that, I'm not sure if [6232] actually fixed anything, setting
`$wp_the_query` in `wp()` seems redundant. As far as I can tell, that line
is never reached, but confirming that would require some more testing.
For now, let's get the unit test in, except for the last assertion, which
apparently cannot be reliably tested.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48844#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list