PHPackages                             webproject-xyz/php-openapi-mock-server - 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. webproject-xyz/php-openapi-mock-server

ActiveLibrary[API Development](/categories/api)

webproject-xyz/php-openapi-mock-server
======================================

A lightweight PHP OpenAPI mock server using Mezzio and PSR-15 middleware.

1.3.4(2mo ago)1676↑45%[1 issues](https://github.com/WebProject-xyz/php-openapi-mock-server/issues)[7 PRs](https://github.com/WebProject-xyz/php-openapi-mock-server/pulls)1MITPHPPHP ~8.3.0 || ~8.4.0 || ~8.5.0CI failing

Since Mar 10Pushed 3w agoCompare

[ Source](https://github.com/WebProject-xyz/php-openapi-mock-server)[ Packagist](https://packagist.org/packages/webproject-xyz/php-openapi-mock-server)[ Docs](https://www.webproject.xyz)[ RSS](/packages/webproject-xyz-php-openapi-mock-server/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (66)Versions (22)Used By (1)

PHP OpenAPI Mock Server
=======================

[](#php-openapi-mock-server)

[![CI](https://github.com/WebProject-xyz/php-openapi-mock-server/actions/workflows/ci.yml/badge.svg)](https://github.com/WebProject-xyz/php-openapi-mock-server/actions/workflows/ci.yml)[![PHP Version](https://camo.githubusercontent.com/e69fc10ad0d3845d44d08b0eeedd6dd7a5bfa4ab872e68e26b131554122d35d5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![PHPStan](https://camo.githubusercontent.com/d117944b58da8146f96b4ef7403807610a20eeb3fbcaaaf95157bbcdad1686eb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230382d627269676874677265656e2e737667)](https://phpstan.org/)[![Coverage](https://camo.githubusercontent.com/4caf430a4ee8d9bf74233dcfcccabf927b298394460768546b895849170c0b3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d38322532352d627269676874677265656e2e737667)](tests/_output/coverage.txt)

> **A high-performance, lightweight, zero-docker OpenAPI 3.x mock server built with Mezzio.**

This project provides a standalone PHP application that serves dynamic mock data based on your OpenAPI specification. It is optimized for speed, low memory footprint, and seamless CI integration.

---

🚀 Features
----------

[](#-features)

- **Blazing Fast:** Sub-millisecond initialization and ~4ms request processing.
- **Interactive Documentation:** Integrated **Swagger UI** at the root (`/`) for real-time spec exploration.
- **Stateless Service Architecture:** Built with a high-performance `FakerRegistry` for efficient service management.
- **Type-Safe Enums:** Robust implementation using PHP 8.3 Enums for `MockStrategy`, `HttpMethod`, `FakerType`, and `FakerContext`.
- **PSR-15 Compliant:** Built on the industrial-strength [Mezzio](https://docs.mezzio.dev/) middleware stack.
- **Docker Ready:** Production-ready [FrankenPHP](https://frankenphp.dev/) image with **Hot-Reload** support for development.
- **Intelligent Faking:** Automatically generates realistic mock data using spec `examples`, `defaults`, and schema constraints (`anyOf`, `oneOf`, `allOf`).
- **OpenAPI 3.1 Support:** Advanced support for numeric exclusive constraints and modern spec features.
- **Smart Caching:** Built-in **PSR-6 caching** and **schema memoization** to eliminate redundant parsing and resolution.
- **Validation:** Optional request and response validation to ensure your clients and mocks stay in sync.
- **Problem Details:** Native support for [RFC 7807](https://tools.ietf.org/html/rfc7807) error responses with detailed diagnostics.

---

📦 Installation
--------------

[](#-installation)

```
git clone https://github.com/WebProject-xyz/php-openapi-mock-server.git
cd php-openapi-mock-server
composer install
```

*Requires PHP `^8.3` with `opcache` enabled for best performance.*

---

🖥️ Usage
--------

[](#️-usage)

### Start the Server

[](#start-the-server)

```
php -S localhost:8080 -t public
```

### Docker

[](#docker)

You can also run the mock server using Docker or Docker Compose (powered by [FrankenPHP](https://frankenphp.dev/)).

#### Using Docker Compose (with Hot-Reload)

[](#using-docker-compose-with-hot-reload)

The `compose.yml` is configured to mount your local code, allowing for real-time updates during development.

```
# Start with default spec (data/openapi.yaml)
docker compose up -d

# Start with a specific local spec
OPENAPI_SPEC=data/my-spec.yaml docker compose up -d

# Start with a remote URL
OPENAPI_SPEC=https://example.com/openapi.yaml docker compose up -d
```

#### Using Docker

[](#using-docker)

```
docker build -t openapi-mock-server .
docker run -d -p 8080:80 -e OPENAPI_SPEC=data/openapi.yaml openapi-mock-server
```

### Advanced Configuration

[](#advanced-configuration)

You can control the server via environment variables or headers:

Variable / HeaderDescriptionDefault`OPENAPI_SPEC`Path or URL to your `.yaml` or `.json` spec.`data/openapi.yaml``X-OpenApi-Mock-Active`Toggle mock server activation (`true`/`false`).`true``X-OpenApi-Mock-StatusCode`Force a specific response status code.*Automatic Fallback*`X-OpenApi-Mock-Example`Force a specific named example from the spec.`default`---

📊 Performance
-------------

[](#-performance)

We take performance seriously. Using **PHPBench**, we track the overhead of our middleware and faking logic.

### Benchmark Results

[](#benchmark-results)

*Running on PHP 8.3 with OPcache &amp; JIT enabled.*

OperationAverage TimeMemory Usage**Middleware Creation****~21.0 μs**~6.0 MB**Full Mock Request****~4.20 ms**~6.0 MB> *Note: Metrics include full Request Validation + Schema Resolution + Data Generation + Response Validation.*

To run benchmarks locally:

```
composer bench
```

---

🛠️ Development &amp; Testing
----------------------------

[](#️-development--testing)

We maintain high code quality standards:

- **Unit Tests**: Full coverage of fakers, validators, and factories.
- **Acceptance Tests**: End-to-end verification using the built-in PHP server.
- **Static Analysis**: PHPStan Level 8 (Strict).
- **Refactoring**: Rector PHP 8.3 ruleset.

### Key Commands

[](#key-commands)

```
composer test         # Run all tests (Acceptance + Unit)
composer test:coverage # Generate coverage report (82%+)
composer stan         # Run static analysis
composer rector       # Run refactoring dry-run
composer cs:fix       # Standardize code style
```

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'feat: add some amazing feature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

---

📜 License
---------

[](#-license)

Distributed under the **MIT** License. See `LICENSE` for more information.

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance71

Regular maintenance activity

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 56.4% 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 ~3 days

Recently: every ~8 days

Total

11

Last Release

71d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8126644ebe55d4c9e7d6e496307e6ee2c6232e7af450b1b915de3b282bd44b2d?d=identicon)[Fahl-Design](/maintainers/Fahl-Design)

---

Top Contributors

[![Fahl-Design](https://avatars.githubusercontent.com/u/6690962?v=4)](https://github.com/Fahl-Design "Fahl-Design (31 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (13 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (11 commits)")

###  Code Quality

TestsCodeception

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/webproject-xyz-php-openapi-mock-server/health.svg)

```
[![Health](https://phpackages.com/badges/webproject-xyz-php-openapi-mock-server/health.svg)](https://phpackages.com/packages/webproject-xyz-php-openapi-mock-server)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5733.2M40](/packages/thecodingmachine-graphqlite)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M712](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)

PHPackages © 2026

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