PHPackages                             k-kinzal/oas-fake-php - 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. k-kinzal/oas-fake-php

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

k-kinzal/oas-fake-php
=====================

Intercept HTTP requests, validate against OpenAPI schemas, and generate fake responses for testing

v0.1.0(2d ago)00MITPHPPHP ^8.0CI passing

Since Mar 20Pushed yesterdayCompare

[ Source](https://github.com/k-kinzal/oas-fake-php)[ Packagist](https://packagist.org/packages/k-kinzal/oas-fake-php)[ RSS](/packages/k-kinzal-oas-fake-php/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (11)Versions (4)Used By (0)

OAS Fake PHP
============

[](#oas-fake-php)

[![CI](https://github.com/k-kinzal/oas-fake-php/actions/workflows/ci.yml/badge.svg)](https://github.com/k-kinzal/oas-fake-php/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/d4b5fa4adf514144779a7864904c5e15236c0e798635240c7f6ce9a455657b80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d626c75652e737667)](https://www.php.net/)

OpenAPI schema-driven fake API server for PHP testing. Define your API contract once, and automatically get a working fake server that generates valid responses, validates requests, and catches schema violations in your tests.

Features
--------

[](#features)

- Automatic fake response generation from OpenAPI schema definitions
- Request/response validation against the OpenAPI schema
- Custom response stubs and callbacks per operation
- Declarative server classes with handler methods mapped by `operationId`
- Three operating modes: FAKE, RECORD, REPLAY
- PSR-15 middleware support

Requirements
------------

[](#requirements)

- PHP 8.0+
- ext-curl

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

[](#installation)

```
composer require --dev k-kinzal/oas-fake-php
```

Usage
-----

[](#usage)

### Basic

[](#basic)

Define a server pointing to your OpenAPI schema and start intercepting:

```
use OasFake\OasFake;
use OasFake\Server;

final class PetStoreServer extends Server
{
    protected static string $SCHEMA = __DIR__ . '/openapi.yaml';
}

// Start intercepting HTTP requests
$server = OasFake::start(PetStoreServer::class);

// All HTTP requests now return responses generated from the schema
$client = new GuzzleHttp\Client(['base_uri' => 'https://petstore.example.com']);
$response = $client->get('/pets/1');

// Stop intercepting
OasFake::stop();
```

### Custom Responses

[](#custom-responses)

Override responses for specific operations using the configure callback:

```
use OasFake\OasFake;
use OasFake\Handler;

$server = OasFake::start(PetStoreServer::class, fn ($s) => $s
    ->withResponse('listPets', 200, [['id' => 1, 'name' => 'Buddy']])
    ->withCallback('createPet', function ($request, $response) {
        $body = json_decode((string) $request->getBody(), true);
        return new \GuzzleHttp\Psr7\Response(201, [], json_encode([
            'id' => 42,
            'name' => $body['name'],
        ]));
    })
    ->withHandler('deletePet', Handler::status(204))
);
```

### Declarative Server

[](#declarative-server)

Public methods on a `Server` subclass are automatically registered as handlers, matched by `operationId`:

```
use OasFake\Server;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class PetStoreServer extends Server
{
    protected static string $SCHEMA = __DIR__ . '/openapi.yaml';

    public function listPets(ServerRequestInterface $request, ?ResponseInterface $response): ResponseInterface
    {
        return new Response(200, ['Content-Type' => 'application/json'], json_encode([
            ['id' => 1, 'name' => 'Buddy'],
        ]));
    }

    #[\OasFake\Route(method: 'DELETE', path: '/pets/{petId}')]
    public function removePet(ServerRequestInterface $request, ?ResponseInterface $response): ResponseInterface
    {
        return new Response(204);
    }
}
```

### Configuration

[](#configuration)

```
use OasFake\OasFake;
use OasFake\Mode;

$server = OasFake::start(PetStoreServer::class, fn ($s) => $s
    ->withMode(Mode::RECORD)  // or ->withMode('record')
    ->withCassettePath('./fixtures/cassettes')
    ->withRequestValidation(false)
    ->withResponseValidation(false)
    ->withFakerOptions(['alwaysFakeOptionals' => true, 'minItems' => 2, 'maxItems' => 5])
    ->withMiddleware(new MyMiddleware())
);
```

All settings can also be overridden via environment variables:

```
OAS_FAKE_MODE=record OAS_FAKE_VALIDATE_REQUESTS=false composer test
```

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

35

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

2d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4458a22db62c885006248e08715301bcb73e78c1057e2bbf686af001729165d5?d=identicon)[kinzal](/maintainers/kinzal)

---

Top Contributors

[![k-kinzal](https://avatars.githubusercontent.com/u/1281825?v=4)](https://github.com/k-kinzal "k-kinzal (8 commits)")

---

Tags

api-testingfake-servermock-serveropenapiopenapi-mockphpphp-testingphp-vcrtestinghttptestingcurlGuzzleswaggeropenapimockfakevcr

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/k-kinzal-oas-fake-php/health.svg)

```
[![Health](https://phpackages.com/badges/k-kinzal-oas-fake-php/health.svg)](https://phpackages.com/packages/k-kinzal-oas-fake-php)
```

###  Alternatives

[osteel/openapi-httpfoundation-testing

Validate HttpFoundation requests and responses against OpenAPI (3+) definitions

1191.9M5](/packages/osteel-openapi-httpfoundation-testing)[doppiogancio/mocked-client

A simple way to mock a client

1974.3k1](/packages/doppiogancio-mocked-client)[aeris/guzzle-http-mock

A mock library for verifying requests made with the Guzzle Http Client, and mocking responses.

2713.1k1](/packages/aeris-guzzle-http-mock)[ybelenko/openapi-data-mocker

Library that generates fake data from Swagger 2.0|Openapi 3.0 spec

1230.5k](/packages/ybelenko-openapi-data-mocker)[ikwattro/guzzle-stereo

Guzzle Recorder for recording Request/Responses and replay them back in a Mock

782.6k](/packages/ikwattro-guzzle-stereo)[phpcurl/curlwrapper

The simplest OOP wrapper for curl, curl\_multi, curl\_share functions. Use CURL as a dependency, not hard-coded!

11109.7k3](/packages/phpcurl-curlwrapper)

PHPackages © 2026

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