A HTTP server mock for automated tests.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
src
tests
.gitignore
.php_cs.dist
.travis.yml
CHANGELOG.md
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

HttpMock

Build status Latest Stable Version License

A HTTP server mock for automated tests.

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.