Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

About

A HTTP server mock for automated tests.

Topics

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.