PHPackages                             bneumann/mock-api-bundle - 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. bneumann/mock-api-bundle

ActiveSymfony-bundle[API Development](/categories/api)

bneumann/mock-api-bundle
========================

A Symfony bundle to mock external API responses

23PHP

Since Aug 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bneumann97/mock-api-bundle)[ Packagist](https://packagist.org/packages/bneumann/mock-api-bundle)[ RSS](/packages/bneumann-mock-api-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Mock API Bundle
===============

[](#mock-api-bundle)

The Mock API Bundle is a Symfony bundle designed to help you mock API requests for testing purposes. It allows you to define mock responses for specific requests using YAML configuration files, making it easier to write integration tests without relying on external services. This is especially useful when you need to test third-party API integrations or when you want to simulate different scenarios in your tests.

**This will only work in tests, the normal HTTP client behavior will not be affected.**

Features
--------

[](#features)

- Mock HTTP requests based on URL and request body.
- Define mock responses in YAML files.
- Seamless integration with Symfony's HTTP client.
- Service decoration to ensure usage only in test environments.

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

[](#installation)

1. Add the bundle to your Symfony project using Composer:

```
composer require bneumann/mock-api-bundle --dev
```

2. Register the bundle in your `config/bundles.php` file:

```
return [
    // ...
    Bneumann\MockApiBundle\BneumannMockApiBundle::class => ['test' => true],
];
```

3. **(Optional)** Configure the bundle by creating a `bneumann_mock_api.yaml` file in your `config/packages/test` directory:

```
bneumann_mock_api:
    mocks_path: tests/mocks
```

Usage
-----

[](#usage)

To start using the Mock API Bundle, you need to create one or multiple mock configuration file in the directory specified by the `mocks_path` configuration option (default is `tests/mocks`). This file should contain a list of mock responses, each with an URL, method and optional request body for POST and the response data with status code and a body you want to return.

Here's an example of a mock configuration file:

```
mocks:
    - url: https://example.com/api/users
      method: GET
      response:
          status: 200
          body:
              [
                  {
                      "id": 1,
                      "name": "John Doe"
                  },
                  {
                      "id": 2,
                      "name": "Jane Doe"
                  }
              ]
    - url: https://example.com/api/users
      method: POST
      request:
          body:
              name: Alice
      response:
          status: 201
          body:
              {
                  "id": 3,
                  "name": "Alice"
              }
```

You can declare the body or the response and request as JSON or YAML. The example above uses JSON for the response and YAML for the request just for demonstration purposes.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue to help improve this bundle.

License
-------

[](#license)

This bundle is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/45589752?v=4)[Basti](/maintainers/bneumann97)[@bneumann97](https://github.com/bneumann97)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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