PHPackages                             saritasa/openapi-httpfoundation-testing - 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. saritasa/openapi-httpfoundation-testing

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

saritasa/openapi-httpfoundation-testing
=======================================

Strengthen your API tests by validating HttpFoundation responses against OpenAPI (3.0.x) definitions

1.0.1(5y ago)08971MITPHPPHP ^7.2

Since Jan 6Pushed 5y agoCompare

[ Source](https://github.com/Saritasa/php-openapi-testing)[ Packagist](https://packagist.org/packages/saritasa/openapi-httpfoundation-testing)[ Docs](https://github.com/osteel/openapi-httpfoundation-testing)[ RSS](/packages/saritasa-openapi-httpfoundation-testing/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (7)Versions (4)Used By (0)

OpenAPI HttpFoundation Testing
==============================

[](#openapi-httpfoundation-testing)

[![Latest Stable Version](https://camo.githubusercontent.com/234a3c24a98a930de7fc99fe0a80108d8d50ebb01e4e90405dc7dd434052103f/68747470733a2f2f706f7365722e707567782e6f72672f6f737465656c2f6f70656e6170692d68747470666f756e646174696f6e2d74657374696e672f76)](//packagist.org/packages/osteel/openapi-httpfoundation-testing)[![License](https://camo.githubusercontent.com/150045ce7f42401663f9ab8b705d6d3f0b42cd7c13f7f9dd4939e9535cc9ee1f/68747470733a2f2f706f7365722e707567782e6f72672f6f737465656c2f6f70656e6170692d68747470666f756e646174696f6e2d74657374696e672f6c6963656e7365)](//packagist.org/packages/osteel/openapi-httpfoundation-testing)[![Build Status](https://camo.githubusercontent.com/885174d9465b5d5ab8fd18b82f2f0489f289437061412aec306f730f3eea014e/68747470733a2f2f7472617669732d63692e636f6d2f6f737465656c2f6f70656e6170692d68747470666f756e646174696f6e2d74657374696e672e7376673f746f6b656e3d53447838656579536e44707a7377704c56545533266272616e63683d6d61696e)](https://travis-ci.com/osteel/openapi-httpfoundation-testing)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f6bf84f80c8508facabe1f0cc8763fc8cdbeea283feecca009950deedb11a5ef/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f737465656c2f6f70656e6170692d68747470666f756e646174696f6e2d74657374696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e26733d62656639646462663239646163363936313261333039326534373631653134636537363862636364)](https://scrutinizer-ci.com/g/osteel/openapi-httpfoundation-testing/?branch=main)

Strengthen your API tests by validating HttpFoundation responses against OpenAPI (3.0.x) definitions.

See [this article](https://tech.osteel.me/posts/openapi-backed-api-testing-in-php-projects-a-laravel-example "OpenAPI-backed API testing in PHP projects – a Laravel example") for more details, and [this repository](https://github.com/osteel/openapi-httpfoundation-testing-laravel-example) for an example use in a Laravel project.

Why?
----

[](#why)

[OpenAPI](https://swagger.io/specification/) is a specification intended to describe RESTful APIs in a way that is understood by humans and machines alike.

By validating an API's responses against the OpenAPI definition that describes it, we guarantee that the API's behaviour conforms to the documentation we provide, thus making the OpenAPI definition the single source of truth.

The [HttpFoundation component](https://symfony.com/doc/current/components/http_foundation.html) is developed and maintained as part of the [Symfony framework](https://symfony.com/). It is used to handle HTTP requests and responses in projects such as Symfony, Laravel, Drupal, and many other major industry players (see the [extended list](https://symfony.com/components/HttpFoundation)).

How does it work?
-----------------

[](#how-does-it-work)

This package is built upon the [OpenAPI PSR-7 Message Validator](https://github.com/thephpleague/openapi-psr7-validator) package, which validates [PSR-7 messages](https://www.php-fig.org/psr/psr-7/) against OpenAPI definitions.

It essentially converts HttpFoundation response objects to PSR-7 messages using Symfony's [PSR-7 Bridge](https://symfony.com/doc/current/components/psr7.html) and [Tobias Nyholm](https://github.com/Nyholm)'s [PSR-7 implementation](https://github.com/Nyholm/psr7), before passing them on to the OpenAPI PSR-7 Message Validator.

Install
-------

[](#install)

Via Composer:

```
$ composer require --dev osteel/openapi-httpfoundation-testing
```

> 💡 This package is meant to be used for development only, as part of your API test suite.

Usage
-----

[](#usage)

First, import the builder in the class that will perform the validation:

```
use Osteel\OpenApi\Testing\ResponseValidatorBuilder;
```

Use the builder to create a `Osteel\OpenApi\Testing\ResponseValidator` object, feeding it a YAML or JSON OpenAPI definition:

```
$validator = ResponseValidatorBuilder::fromYaml('my-definition.yaml')->getValidator();

// or

$validator = ResponseValidatorBuilder::fromJson('my-definition.json')->getValidator();
```

> 💡 Instead of a file, you can also pass a YAML or JSON string directly.

You can now validate a `Symfony\Component\HttpFoundation\Response` object for a given [path](https://swagger.io/specification/#paths-object) and method:

```
$validator->validate('/users', 'post', $response);
```

> 💡 For convenience, responses implementing `Psr\Http\Message\ResponseInterface` are also accepted.

In the example above, we check that the response matches the OpenAPI definition for a `POST` request on the `/users` path.

Each of OpenAPI's supported HTTP methods (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` and `TRACE`) also has a shortcut method that calls `validate` under the hood, meaning the line above could also be written this way:

```
$validator->post('/users', $response);
```

The `validate` method returns `true` in case of success, and throws [PSR-7 message-related exceptions](https://github.com/thephpleague/openapi-psr7-validator#exceptions) from the underlying OpenAPI PSR-7 Message Validator package in case of error.

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

[](#change-log)

Please see the [Releases section](../../releases) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Credits
-------

[](#credits)

**People**

- [Yannick Chenot](https://github.com/osteel)
- [All Contributors](../../contributors)

Special thanks to [Pavel Batanov](https://github.com/scaytrase) for his advice on structuring the package.

**Packages**

- [OpenAPI PSR-7 Message Validator](https://github.com/thephpleague/openapi-psr7-validator)
- [The PSR-7 Bridge](https://symfony.com/doc/current/components/psr7.html)
- [PSR-7 implementation](https://github.com/Nyholm/psr7)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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 ~14 days

Total

2

Last Release

1939d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7632cf2eb5dd552ace9d66947ed6919e19c6a2fdb5dc73b8c71e0f9886ccc83?d=identicon)[saritasa](/maintainers/saritasa)

---

Top Contributors

[![osteel](https://avatars.githubusercontent.com/u/436467?v=4)](https://github.com/osteel "osteel (7 commits)")[![populov](https://avatars.githubusercontent.com/u/3766033?v=4)](https://github.com/populov "populov (2 commits)")

---

Tags

httptestingapisymfonylaravelvalidationopenapihttpfoundation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/saritasa-openapi-httpfoundation-testing/health.svg)

```
[![Health](https://phpackages.com/badges/saritasa-openapi-httpfoundation-testing/health.svg)](https://phpackages.com/packages/saritasa-openapi-httpfoundation-testing)
```

###  Alternatives

[osteel/openapi-httpfoundation-testing

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

1201.9M6](/packages/osteel-openapi-httpfoundation-testing)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[kirschbaum-development/laravel-openapi-validator

Automatic OpenAPI validation for Laravel HTTP tests

581.1M5](/packages/kirschbaum-development-laravel-openapi-validator)[mattiasgeniar/phpunit-query-count-assertions

A custom assertion for phpunit that allows you to count the amount of SQL queries used in a test. Can be used to enforce certain performance characteristics (ie: limit queries to X for a certain action).

160730.9k2](/packages/mattiasgeniar-phpunit-query-count-assertions)

PHPackages © 2026

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