easy-http/mock-builder

A fluid interface to build HTTP mocks with an expressive syntax

v1.2.0 2023-09-25 01:18 UTC

This package is auto-updated.

Last update: 2024-04-25 02:28:31 UTC


README

68747470733a2f2f626c6f672e706c656574732e6f72672f696d672f61727469636c65732f656173792d687474702d6c6f676f2d3332302e706e67

Build Status Code Quality Code Coverage

#StandWithUkraine

PHP Versions Supported Total Downloads

🚀 Mock HTTP services

Mock builder

A fluid interface to build HTTP mocks with an expressive syntax. You can use this library to build mocks for Guzzle, Symfony and other HTTP Clients.

Bugs Bugs Bugs

This library supports the following versions of Guzzle Http Client.

PHP Versions Supported PHP Versions Supported

🔧 Installation

Use following command to install this library:

composer require easy-http/mock-builder

💡 Usage

Creating a simple Mock for Guzzle

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

📚 Check out the Documentation to learn how to use this library.