PHP code example of e-moe / guzzle-regexp-mock-plugin

1. Go to this page and download the library: Download e-moe/guzzle-regexp-mock-plugin 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/ */

    

e-moe / guzzle-regexp-mock-plugin example snippets


use Guzzle\Http\Client;
use Guzzle\Http\Message\Response;
use Emoe\GuzzleRegexpMockPlugin\MockPlugin;

$client = new Client('http://www.test.com/');

$mock = new MockPlugin();
$mock->addResponse(new Response(200), '/(foo|bar)page/')
     ->addResponse(new Response(200), '/article\/\w+/')
     ->addResponse(new Response(404)); // regexp pattern is optional

// Add the mock plugin to the client object
$client->addSubscriber($mock);

// The following request will receive a 200 response from the plugin regexp queue
$client->get('/foopage')->send();

// The following request will receive a 404 response from the plugin, default behaviour
$client->get('notfound')->send();

// The following request will receive a 200 response from the plugin regexp queue
$client->get('/article/about')->send();