1. Go to this page and download the library: Download alperakgun/wp_nock library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alperakgun / wp_nock example snippets
use Alperakgun\Testing\WP_Nock;
use Alperakgun\Testing\WP_Nock_Exception;
class Test_My_Cool_WordPress_Plugin extends WP_UnitTestCase {
const TEST_URL = 'https://www.wordpress.com/test';
# Testing wp_remote_get, or wp_remote_post is similar
public function test_wp_nock_wp_remote_get() {
$nock = new WP_Nock();
$nock->set_up();
$nock->get(
self::TEST_URL,
array(
'response' => array(
'code' => 200,
),
'body' => '{"foo":"bar"}',
)
);
$result = wp_remote_get( self::TEST_URL );
$this->assertSame( $result['response']['code'], 200 );
$this->assertSame( $result['body'], '{"foo":"bar"}' );
$nock->tear_down();
}
public function test_wp_nock_wp_redirect_with_callback() {
$nock = new WP_Nock();
$nock->set_up();
$nock->redirect(
self::TEST_URL,
function( $payload ) {
$this->assertSame( $payload['location'], self::TEST_URL );
return false;
}
);
wp_redirect( self::TEST_URL );
$nock->tear_down();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.