WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 3 years 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 (2)

#1 @rmccue
4 years 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.

This ticket was mentioned in Slack in #core-restapi by chrisl27. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.