PHPackages                             genesis/mock-api - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. genesis/mock-api

ActiveLibrary[Testing &amp; Quality](/categories/testing)

genesis/mock-api
================

Develop and run automated tests against a mock API.

1.2.1(5y ago)016[6 issues](https://github.com/forceedge01/api-mocker/issues)[3 PRs](https://github.com/forceedge01/api-mocker/pulls)MITPHPPHP ~7.1

Since Jul 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/forceedge01/api-mocker)[ Packagist](https://packagist.org/packages/genesis/mock-api)[ RSS](/packages/genesis-mock-api/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (12)Used By (0)

API mocker [![Build Status](https://camo.githubusercontent.com/627bf91c8c65ddf919f8ddc59aa3dcb622570d11c324d141189f52d9b8e7dfae/68747470733a2f2f7472617669732d63692e636f6d2f666f7263656564676530312f6170692d6d6f636b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/forceedge01/api-mocker) [![Latest Stable Version](https://camo.githubusercontent.com/ae0117b7e4563e623ede1ecc71c1b610701621e4bdda8099fe3dc90337d49b1e/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f6d6f636b2d6170692f76)](//packagist.org/packages/genesis/mock-api) [![License](https://camo.githubusercontent.com/d2e8290e2f11582bf0ce2e349aab80dc8f6c2cb11cc964c760b75c8f14f89734/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f6d6f636b2d6170692f6c6963656e7365)](//packagist.org/packages/genesis/mock-api) [![Latest Unstable Version](https://camo.githubusercontent.com/d8e0a24ede2897c7b097417eb1bcfd274966bb82b53a7bf75074a31698b3926e/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f6d6f636b2d6170692f762f756e737461626c65)](//packagist.org/packages/genesis/mock-api)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#api-mocker----)

Have an application that depends on an API but is too much of a burden on testing? Replace your API with a mock API using this package and mock requests on the fly.

How to install
--------------

[](#how-to-install)

```
composer require genesis/mock-api
make -f ./vendor/genesis/mock-api/Makefile build
make mockapi-install

```

Start mock-api:

```
make mockapi-up

```

Test that the mock API is running:

```
curl http://0.0.0.0:8989/alive

```

Stop mock-api:

```
make mockapi-down

```

Find more commands in the generated Makefile.

Static mocks
------------

[](#static-mocks)

You can add your static routes (ones that will be available as soon as you boot up the mock API) in the staticMocks folder. The data format is defined below and example request already exists.

Dynamic mocks
-------------

[](#dynamic-mocks)

To mock a request `POST` your mocking request to `/mocks` with `mockData` json. Example mock request:

```
# POST /mocks
{
    "mockData": {
        "url": "/user/abc123",
        "get": [{
            "body": {
                "id": "abc123",
                "name": "Wahab Qureshi"
            }
        }]
     }
}
```

You can override a static mock with a dynamic one. Purging the mocks will revert the back to the static mock.

Full mock data options:

```
{
    "mockData": {
        "url": "/user/abc123",
        "get": [{
            "with": "/abc123/",
            "response_code": 301,
            "headers": {"lola": "123", "baby boo": "dudu"},
            "body": {
                "id": "abc123",
                "name": "Wahab Qureshi"
            },
            "proxy": {
                "url": "http://google.com",
                "headers": {
                    "app-token": "88374783847"
                }
            },
            "consecutive_responses": [{
                "response_code": 205,
                "body": {
                    "id": "abc123",
                    "name": "Wahab Qureshi"
                }
            }, {
                "response_code": 500,
                "body": "internal server error"
            }]
        }]
     }
}
```

`mockData (object)`: Contains mock request information.

`mockData.url (string)`: The URL to mock, can be an existing statically mocked URL.

`mockData. ([]object)`: The method to mock for the URL.

`mockData..with (?string)`: A regex pattern to be applied to the URL optionally.

`mockData..response_code (?int)`: The response code to return optionally.

`mockData..headers (?object)`: The headers to return.

`mockData..body (mixed)`: The response content.

`mockData..consecutive_responses (?[]object)`: On consecutive calls return one after the other. Supports response\_code, headers and body.

`mockData..proxy (?object)`: Proxy the response through another URL.

View mocked endpoints
---------------------

[](#view-mocked-endpoints)

View existing mock requests by visiting `/mocks`

Purge dynamic mocks
-------------------

[](#purge-dynamic-mocks)

To purge all dynamic mocks created send `GET` request to `/mocks?purge=true`

Development:
------------

[](#development)

Running tests is just a case of running the behat tests:

```
./vendor/bin/behat

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

8

Last Release

2154d ago

Major Versions

0.3.0 → 1.0.02020-07-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3443293?v=4)[Wahab Qureshi](/maintainers/forceedge)[@forceedge](https://github.com/forceedge)

---

Top Contributors

[![forceedge01](https://avatars.githubusercontent.com/u/1619816?v=4)](https://github.com/forceedge01 "forceedge01 (14 commits)")

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/genesis-mock-api/health.svg)

```
[![Health](https://phpackages.com/badges/genesis-mock-api/health.svg)](https://phpackages.com/packages/genesis-mock-api)
```

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M361](/packages/dms-phpunit-arraysubset-asserts)[mcustiel/phiremock-server

A mocker for HTTP and REST services

19890.1k13](/packages/mcustiel-phiremock-server)[discord-php/http

Handles HTTP requests to Discord servers

24360.3k12](/packages/discord-php-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
