jfalque / http-mock
Allows to create HTTP fixtures to mock tests
Installs: 67 161
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7
- guzzlehttp/psr7: ~1.0
- psr/http-message: ~1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: 2.0.*
- mikey179/vfsstream: 1.6.*
- phpunit/phpunit: 6.0.*
This package is not auto-updated.
Last update: 2020-11-28 09:47:54 UTC
README
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.