PHPackages                             elnoro/php-http-mock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. elnoro/php-http-mock

ActiveLibrary[HTTP &amp; Networking](/categories/http)

elnoro/php-http-mock
====================

A simple solution to mock external APIs using local php server (no binary deps)

00PHP

Since Oct 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/elnoro/php-http-mock)[ Packagist](https://packagist.org/packages/elnoro/php-http-mock)[ RSS](/packages/elnoro-php-http-mock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

php-http-mock
=============

[](#php-http-mock)

[![ci](https://github.com/elnoro/php-http-mock/actions/workflows/php.yml/badge.svg)](https://github.com/elnoro/php-http-mock/actions/workflows/php.yml/badge.svg)[![coverage](https://camo.githubusercontent.com/632e690bd485cc8e8a54abfc6f6b112786c250789fbf3d05329ec408512d5288/68747470733a2f2f636f6465636f762e696f2f67682f656c6e6f726f2f7068702d687474702d6d6f636b2f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://app.codecov.io/gh/elnoro/php-http-mock)

A simple solution to mock external APIs using local php server without binary deps

Designed for PHPUnit, but you can use it with anything.

How it works
------------

[](#how-it-works)

Whenever you call ApiMocker::start, a new local php server is launched (via php -S).

The server reads its route configuration (URLs, methods, and corresponding responses) from a temporary file. This file is re-read on every request, so you can reconfigure routes and responses after the server is started.

The file is written to and created by the php-http-mock package automatically and passed to the server via an env variable.

Example
-------

[](#example)

```
