PHP code example of easy-http / mock-builder
1. Go to this page and download the library: Download easy-http/mock-builder 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/ */
easy-http / mock-builder example snippets
use EasyHttp\MockBuilder\HttpMock;
use EasyHttp\MockBuilder\MockBuilder;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;
$builder = new MockBuilder();
$builder
->when()
->pathIs('/v1/products')
->methodIs('POST')
->then()
->body('bar');
$mock = new HttpMock($builder);
$client = new Client(['handler' => HandlerStack::create($mock)]);
$client
->post('/v1/products')
->getBody()
->getContents(); // bar