PHPackages                             pbxapi/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. [HTTP &amp; Networking](/categories/http)
4. /
5. pbxapi/php-http-fixture-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

pbxapi/php-http-fixture-client
==============================

Fixture client for PHP-HTTP

2.2.0(7y ago)0272MITPHPPHP ^7.0

Since Feb 9Pushed 5y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (5)Used By (0)

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)[![Build Status](https://camo.githubusercontent.com/0acb397acc6dc5891b25194c960e14f1c8d21f20607e13b8fef30bee2108b98c/68747470733a2f2f7472617669732d63692e6f72672f737769736e6c2f7068702d687474702d666978747572652d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/swisnl/php-http-fixture-client)[![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/18c919ccf015240637f952c01c589455387b8af316c33432b6cb1a540fe1fdf8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532334439303231422e737667)](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 \Pbxapi\Http\Fixture\ResponseBuilder('/path/to/fixtures');
$client = new \Pbxapi\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### 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.

SWIS
----

[](#swis)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 81.3% 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 ~130 days

Total

4

Last Release

2621d ago

Major Versions

1.0.0 → 2.0.02018-09-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bbec96cb6e1fce721fff78c329ed0ecee3aab07e119b0335d70f79af2bb21ba?d=identicon)[pbxhq](/maintainers/pbxhq)

---

Top Contributors

[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (52 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![aaron-1pbx](https://avatars.githubusercontent.com/u/10770444?v=4)](https://github.com/aaron-1pbx "aaron-1pbx (3 commits)")

---

Tags

psr-7clientFixturepsr-18php-httpswisnlswis

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[laudis/neo4j-php-client

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

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

HTTP transport PHP library for Elastic products

1920.6M7](/packages/elastic-transport)[vultr/vultr-php

The Official Vultr API PHP Wrapper.

2243.9k1](/packages/vultr-vultr-php)[chillerlan/php-oauth

A fully transparent, framework agnostic PSR-18 OAuth client.

4210.4k2](/packages/chillerlan-php-oauth)[amphp/http-client-psr7

PSR-7 adapter for Amp's HTTP client.

1454.7k4](/packages/amphp-http-client-psr7)

PHPackages © 2026

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