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-10-25 03:26:00 UTC


README

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.