PHPackages                             swisnl/php-http-fixture-client - 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. swisnl/php-http-fixture-client

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

swisnl/php-http-fixture-client
==============================

Fixture client for PHP-HTTP

3.2.0(2mo ago)961.1k↓36.8%26MITPHPPHP ^8.0CI passing

Since Feb 9Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/swisnl/php-http-fixture-client)[ Packagist](https://packagist.org/packages/swisnl/php-http-fixture-client)[ Docs](https://github.com/swisnl/php-http-fixture-client)[ RSS](/packages/swisnl-php-http-fixture-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (13)Used By (6)

Fixture client for PHP-HTTP
===========================

[](#fixture-client-for-php-http)

[![PHP from Packagist](https://camo.githubusercontent.com/f4adbaca4807ed0e821c30eaf76fa2ab65d66ba4f87a8629cbcaec8f65f02d3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737769736e6c2f7068702d687474702d666978747572652d636c69656e742e737667)](https://packagist.org/packages/swisnl/php-http-fixture-client)[![Latest Version on Packagist](https://camo.githubusercontent.com/0e7f21e76abd34848228109e2b5214aacd20d76aa3705376b1007dd68c5812ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f7068702d687474702d666978747572652d636c69656e742e737667)](https://packagist.org/packages/swisnl/php-http-fixture-client)[![Software License](https://camo.githubusercontent.com/180b2dfb3fa8185e541f1230ee8764241799843c365bd4bc29cd815fce6f2a5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737769736e6c2f7068702d687474702d666978747572652d636c69656e742e737667)](https://github.com/swisnl/php-http-fixture-client/blob/master/LICENSE)[![Buy us a tree](https://camo.githubusercontent.com/195a3f79c3c2f91a69498ad26c1d8a7eeaf5771da0007200f409f5d438a515c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e737667)](https://plant.treeware.earth/swisnl/php-http-fixture-client)[![Build Status](https://camo.githubusercontent.com/19d65241451b92b3c8ce9bd6f01f0ad36b8857b18ec6458e3e83600c71ab5e3f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f737769736e6c2f7068702d687474702d666978747572652d636c69656e742f6d61737465723f6c6162656c3d7465737473)](https://github.com/swisnl/php-http-fixture-client/actions/workflows/tests.yml)[![Scrutinizer Coverage](https://camo.githubusercontent.com/715ac66261ff3ab7f856506cfe4900e8420d6180113592c1a2a0a16a8619892c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f737769736e6c2f7068702d687474702d666978747572652d636c69656e742e737667)](https://scrutinizer-ci.com/g/swisnl/php-http-fixture-client/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/61c7fe6e4d21fd696f602dab81214a64755fe82aa6266a9d2a6fd8d547348aa0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f737769736e6c2f7068702d687474702d666978747572652d636c69656e742e737667)](https://scrutinizer-ci.com/g/swisnl/php-http-fixture-client/?branch=master)[![Made by SWIS](https://camo.githubusercontent.com/8c541545402619860a7346c32a176d63a2b75eb8ebb85590d06a26b62417d260/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e737667)](https://www.swis.nl)

This is a fixture client for PHP-HTTP and is meant for testing purposes. It maps requests to static fixtures.

Install
-------

[](#install)

```
$ composer require --dev swisnl/php-http-fixture-client
```

Usage
-----

[](#usage)

```
// Create client
$responseBuilder = new \Swis\Http\Fixture\ResponseBuilder('/path/to/fixtures');
$client = new \Swis\Http\Fixture\Client($responseBuilder);

// Send request
$response = $client->sendRequest(new Request(...));
```

Fixture mapping
---------------

[](#fixture-mapping)

All requests send using this client are mapped to static fixtures located in the provided path. URLs are transformed to file paths by using the domain and path fragments and (optionally) the method and/or the query params (sorted alphabetically). A list of possible fixture paths is made and handled in order of specificity:

1. {path}.{query}.{method}.mock
2. {path}.{query}.mock
3. {path}.{method}.mock
4. {path}.mock

Please see the following table for some examples.

URLMethodPossible fixtures (in order of specificity)GET/path/to/fixtures/example.com/api/articles/1.get.mock/path/to/fixtures/example.com/api/articles/1.mockPOST/path/to/fixtures/example.com/api/articles.post.mock/path/to/fixtures/example.com/api/articles.mockGET/path/to/fixtures/example.com/api/comments.query=json.get.mock/path/to/fixtures/example.com/api/comments.query=json.mock/path/to/fixtures/example.com/api/comments.get.mock/path/to/fixtures/example.com/api/comments.mock[http://example.com/api/comments?query=json&amp;order=id](http://example.com/api/comments?query=json&order=id)GET/path/to/fixtures/example.com/api/comments.order=id&amp;query=json.get.mock/path/to/fixtures/example.com/api/comments.order=id&amp;query=json.mock/path/to/fixtures/example.com/api/comments.get.mock/path/to/fixtures/example.com/api/comments.mock### Domain aliases

[](#domain-aliases)

The `ReponseBuilder` can be instructed to use aliases for domains using `setDomainAliases([...])`. When configured, the provided aliases will be normalized when transforming requests to file paths. You should provide aliases in the form of `['alias' => 'abstract']`.

### Ignored query parameters

[](#ignored-query-parameters)

The `ReponseBuilder` can be instructed to ignore certain query parameters using `setIgnoredQueryParameters([...])`. When configured, the provided parameters will be ignored when transforming requests to file paths. You should only provide the parameter name, not the value. This allows you to ignore 'dynamic' parameters that change in each test execution. Parameters are matched strictly, after url decoding, so 'foo' will match 'foo=bar', but not 'foo\[\]=bar'.

### Strict mode

[](#strict-mode)

The `ReponseBuilder` can be set to strict mode using `setStrictMode(true)`. When in strict mode, only the first possible fixture path will be used. This means that both the method and query params must be present in the fixture file name and it does not fall back to other fixture files.

### Helper

[](#helper)

Please see [](https://swisnl.github.io/php-http-fixture-client/#helper) for the URL helper.

### Body

[](#body)

The body of a request is loaded directly from a fixture with the file extension *.mock*. The contents of this file can be anything that is a valid HTTP response, e.g. HTML, JSON or even images. If a fixture can not be found, a `MockNotFoundException` will be thrown. This exception has a convenience method `getPossiblePaths()` which lists all file paths that were checked, in order of specificity.

### Headers (optional)

[](#headers-optional)

The headers of a request are loaded from a fixture with the file extension *.headers*. This is a simple JSON object with headers, e.g.

```
{
  "X-Made-With": "PHPUnit"
}
```

### Status (optional)

[](#status-optional)

The status code of a request is loaded from a fixture with the file extension *.status*. This is a plain file containing only the [HTTP status code](https://httpstatuses.com/). If no *.status* file is found, *200 OK* will be used.

Mocks (advanced)
----------------

[](#mocks-advanced)

This client extends [php-http/mock-client](https://github.com/php-http/mock-client), which allows you to add custom responses and exceptions that ignore fixture files. Please see the [mock-client documentation](https://github.com/php-http/mock-client#documentation) for more information.

N.B. A default response can not be set because this client uses that under the hood.

Change log
----------

[](#change-log)

Please see [CHANGELOG](https://github.com/swisnl/php-http-fixture-client/blob/master/CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/swisnl/php-http-fixture-client/blob/master/CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](https://github.com/swisnl/php-http-fixture-client/blob/master/CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/swisnl/php-http-fixture-client/blob/master/LICENSE.md) for more information.

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/php-http-fixture-client) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source
-------------------

[](#swis-heart-open-source)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance88

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 74.7% 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 ~269 days

Recently: every ~383 days

Total

12

Last Release

60d ago

Major Versions

1.0.0 → 2.0.02018-09-05

2.x-dev → 3.0.02022-01-10

PHP version history (4 changes)1.0.0PHP ^7.0

2.3.0PHP ^7.2|^8.0

3.0.0PHP ^7.4|^8.0

3.2.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8734305?v=4)[SWIS](/maintainers/swisnl)[@swisnl](https://github.com/swisnl)

---

Top Contributors

[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (133 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (37 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

clientfixturehacktoberfestmockphp-httppsr-7testingpsr-7testingclientFixturepsr-18php-httpswisnlswis

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/swisnl-php-http-fixture-client/health.svg)

```
[![Health](https://phpackages.com/badges/swisnl-php-http-fixture-client/health.svg)](https://phpackages.com/packages/swisnl-php-http-fixture-client)
```

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[growthbook/growthbook

PHP SDK for GrowthBook, the feature flagging and A/B testing platform

202.9M3](/packages/growthbook-growthbook)[vultr/vultr-php

The Official Vultr API PHP Wrapper.

2243.9k1](/packages/vultr-vultr-php)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)

PHPackages © 2026

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