jfalque/http-mock

This package is abandoned and no longer maintained. No replacement package was suggested.

Allows to create HTTP fixtures to mock tests

v1.0.1 2017-02-05 14:40 UTC

This package is not auto-updated.

Last update: 2020-11-28 09:47:54 UTC


README

Build status Latest Stable Version License

A HTTP server mock for automated tests.

This package is archived and not maintained anymore.

Testing code that makes HTTP calls is not simple: you either need to setup an actual HTTP server that provides the exact responses your tests require, or create mocks with complex assertions and/or expectations.

This package provides a server mock that can handle PSR-7 HTTP requests. It also provides a stream wrapper that integrates the server into PHP's filesystem functions like file_get_contents().

<?php

use Jfalque\HttpMock\Server;

$server = (new Server())
    ->whenUri('http://foo')
        ->return($foo = new Response())
    ->end()
    ->whenUri('http://bar')
        ->return($bar = new Response())
    ->end()
;

$response = $server->handle(new Request('http://foo')); // $foo
$response = $server->handle(new Request('http://bar')); // $bar
$response = $server->handle(new Request('http://baz')); // null

Installation

Run the following Composer command:

$ composer require --dev jfalque/http-mock

More information

Read the documentation for more information.