PHPackages                             karriere/mocky - 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. [API Development](/categories/api)
4. /
5. karriere/mocky

AbandonedArchivedLibrary[API Development](/categories/api)

karriere/mocky
==============

Mocky is a simple API mocking solution written in PHP

v2.1.0(4y ago)312.4k61Apache-2.0PHPPHP ^7.4 | ^8.0

Since Jun 6Pushed 3y agoCompare

[ Source](https://github.com/karriereat/mocky)[ Packagist](https://packagist.org/packages/karriere/mocky)[ RSS](/packages/karriere-mocky/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (2)Versions (6)Used By (1)

[ ![](logo.png)](https://www.karriere.at/)

Mocky - A simple API mock server
================================

[](#mocky---a-simple-api-mock-server)

[![Test](https://github.com/karriereat/mocky/workflows/test/badge.svg)](https://github.com/karriereat/mocky/workflows/test/badge.svg)[![Lint](https://github.com/karriereat/mocky/workflows/lint/badge.svg)](https://github.com/karriereat/mocky/workflows/lint/badge.svg)

Mocky is a simple API mocking solution written in PHP based on the [Slim Framework](https://www.slimframework.com/).

Installation
------------

[](#installation)

You can either create a new mock api by using the `mocky-template` as a starting point

```
composer create-project karriere/mocky-template /destination/path

```

or add mocky as a dependency to your project.

```
composer require karriere/mocky

```

Configuration
-------------

[](#configuration)

With mocky you can define your test cases via JSON. The configuration consists of two file types:

- test files
- mock files

A test file contains all your test endpoints (grouped by the request method) and references one or multiple mock files. The mock file defines the mock data to return. This seperation allows you to reuse mock data over multiple tests.

### Writing a test file

[](#writing-a-test-file)

A test file is stored in the `tests` folder and has the following basic structure

```
{
  "REQUEST_METHOD": {
    "ENDPOINT": {
        "content-type": "application/json",
        "mock": "mock-file.json"
    }
  }
}
```

The test file is a map of request methods (GET, POST, PUT, DELETE, ...). Each request method entry contains a map of endpoints as key and the endpoint definition as value.

Each request definition must define a `content-type` and a `mock` field. The mock field is a reference to the mock data file to deliver.

*Example:*

```
{
  "GET": {
    "/users": {
      "content-type": "application/vnd.api+json",
      "mock": "users/list-users.json"
    },
    "/users/1": {
      "content-type": "application/vnd.api+json",
      "mock": "users/single-user.json"
    }
  }
}
```

#### Structuring your tests

[](#structuring-your-tests)

To be able to structure your test json files by feature a test can be stored in a subfolder.

For example to store multiple tests for a user feature you can create a test under `tests/user/a-test.json`. This test has the following setup route `/setup/{scope}/user/a-test`.

### Writing a mock file

[](#writing-a-mock-file)

A mock file contains an array of mock responses. Each mock response must have a `status` and a `response` field. The `status` field defines the HTTP status code and the `response` field the API response in json format.

Use `example/mocks/users/list-users.json` as a reference.

The mock file uses an array of mock response because you often need different data on subsequent requests.

Lets consider a simple example. You want to test a user feature. Your frontend makes an GET api call to `/users` and receives 2 user entries. Then the test sends a POST to `/users` to create a new user and then executes the GET `/users` again. In the second case 3 user entries should be returned.

Using mocky
-----------

[](#using-mocky)

To deliver your mock data you need to setup your test case. To do so you call the mocky setup endpoint `/setup/{scope}/{test-name}`.

The scope variable is needed to allow parallel access to mocky from different applications. The default scope is called `default`.

**Example:**`http://localhost:8888/setup/default/user-simple`

This endpoint call will setup the `user-simple` test case defined in `tests/user-simple.json`.

To be able to use another scope you simply call the `setup` route with your custom scope name and on each real API call you need to include a request header called `Mocky-Scope` with the custom scope name as value.

[![Mocky Demo](https://camo.githubusercontent.com/7bff98b0b2f3e09c3cccbe711e8892b00721f97e91e3f018a26efd8ca4f8c2d1/687474703a2f2f696d672e796f75747562652e636f6d2f76692f555979574b72624a6a414d2f302e6a7067)](http://www.youtube.com/watch?feature=player_embedded&v=UYyWKrbJjAM)

Webserver Setup
---------------

[](#webserver-setup)

### Built-In PHP Webserver (local development)

[](#built-in-php-webserver-local-development)

```
php -S localhost:8888 -t public public/index.php

```

### Nginx

[](#nginx)

```
server {
    listen 80;
    server_name mocky.example.com;
    index index.php;
    error_log off;
    access_log off;
    root /path/to/public;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
    }
}

```

### Apache

[](#apache)

Your document root points to the `public` directory and you need to make sure that `mod_rewrite` is available.

License
-------

[](#license)

Apache License 2.0 Please see [LICENSE](LICENSE) for more information.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 84.6% 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 ~402 days

Total

5

Last Release

1702d ago

Major Versions

v1.2.0 → v2.0.02020-04-29

PHP version history (2 changes)v2.0.0PHP &gt;=7.2

v2.1.0PHP ^7.4 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b155d5296b644a0e937677b500bee7983ce4a91294b616d7a690e57f5b14a3aa?d=identicon)[fetzi](/maintainers/fetzi)

![](https://avatars.githubusercontent.com/u/24518541?v=4)[karriere-at-dev](/maintainers/karriere-at-dev)[@karriere-at-dev](https://github.com/karriere-at-dev)

---

Top Contributors

[![fetzi](https://avatars.githubusercontent.com/u/3509426?v=4)](https://github.com/fetzi "fetzi (11 commits)")[![jaylinski](https://avatars.githubusercontent.com/u/1668766?v=4)](https://github.com/jaylinski "jaylinski (1 commits)")[![vmonegatto](https://avatars.githubusercontent.com/u/60145326?v=4)](https://github.com/vmonegatto "vmonegatto (1 commits)")

---

Tags

apimock-servermockingphpphp-mocking-frameworkphpmock-serverapi-mocking

### Embed Badge

![Health badge](/badges/karriere-mocky/health.svg)

```
[![Health](https://phpackages.com/badges/karriere-mocky/health.svg)](https://phpackages.com/packages/karriere-mocky)
```

PHPackages © 2026

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