Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#32636 closed defect (bug) (fixed)

$_SERVER['REQUEST_METHOD'] isn't set in the test environment

Reported by: johnbillion's profile johnbillion Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.3 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:


A plugin of mine calls wp_validate_auth_cookie() in its unit tests, but this triggers a PHP notice because this function uses $_SERVER['REQUEST_METHOD'] which isn't set in the WordPress unit test environment.

Attachments (1)

32636.patch (965 bytes) - added by johnbillion 8 years ago.

Download all attachments as: .zip

Change History (6)

8 years ago

#1 @johnbillion
8 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 4.3

32636.patch sets $_SERVER['REQUEST_METHOD'] to GET in the test environment to prevent wp_validate_auth_cookie() triggering a PHP notice.

All tests remain passing with this change.

#2 @boonebgorges
8 years ago

Patch seems good to me, but make sure you check the AJAX tests before committing it, as many of them assume POST and I'm not sure if your change will override that.

#3 @johnbillion
8 years ago

The AJAX tests do indeed pass. They look at DOING_AJAX and the $_POST superglobal, but not the request method.

I've just noticed that Tests_Auth:setUp() explicitly sets $_SERVER['REQUEST_METHOD'] to null, presumably to avoid said PHP notice.

#4 @wonderboymusic
8 years ago

I added that setting to null to avoid said notice. This looks good. This is what I should have done originally.

#5 @wonderboymusic
8 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 32785:

Set $_SERVER['REQUEST_METHOD'] for unit tests.

Props johnbillion.
Fixes #32636.

Note: See TracTickets for help on using tickets.