#41915 closed defect (bug) (wontfix)
REST_REQUEST and parse_request in tests
| Reported by: | drzraf | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Build/Test Tools | Version: | 4.8.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | rest-api |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.