#41915 closed defect (bug) (wontfix)
REST_REQUEST and parse_request in tests
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.8.1 |
| Component: | Build/Test Tools | Keywords: | |
| Focuses: | rest-api | Cc: |
Description
I'm testing a method (an API endpoint) making use of REST_REQUEST.
I found that when the test triggers dispatch(), the endpoint is not correctly initialized:
REST_REQUEST is undefined because phpunit didn't go through wp-blog-header.php > WP->main() > WP->parse_request() at which the rest_api_loaded() function is hooked to.
Change History (2)
Note: See
TracTickets for help on using
tickets.
REST_REQUESTshould be avoided where possible, because it can only be turned on, not off. We set this only when a request comes in through a request to/wp-json/*, and it's not set in unit tests or when usingrest_do_request()internally.There's no way to set this during tests, and we don't recommend it in any case, so closing this as wontfix.