Skip to content

Instantly share code, notes, and snippets.

@tlovett1
Created June 2, 2014 15:34
Show Gist options
  • Save tlovett1/e9ea0a2a3e76004beab4 to your computer and use it in GitHub Desktop.
Save tlovett1/e9ea0a2a3e76004beab4 to your computer and use it in GitHub Desktop.
WP Mock wp_remote_request
<?php
class ESTestCore extends PHPUnit_Framework_TestCase {
public function setUp() {
\WP_Mock::setUp();
}
public function tearDown() {
\WP_Mock::tearDown();
}
public function testRemoteRequest() {
$response = array(
'body' => '{"success": 1}',
'response' => array(
'code' => 200,
'message' => 'OK',
),
'cookies' => array(),
'filename' => null,
);
\WP_Mock::wpFunction( 'wp_remote_request', array(
'times' => 1,
'args' => array( 'http://test.com', '*' ),
'return' => $response
) );
$return = wp_remote_request( 'http://test.com', json_encode( array( 'test' => true ) ) );
$this->assertEquals( $return, $response );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment