WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 2 months ago

#41915 closed defect (bug) (wontfix)

REST_REQUEST and parse_request in tests

Reported by: drzraf 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 (1)

#1 @rmccue
2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

REST_REQUEST should 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 using rest_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.

Note: See TracTickets for help on using tickets.