PHPackages                             phauthentic/phpunit-openapi-assertions - 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. phauthentic/phpunit-openapi-assertions

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

phauthentic/phpunit-openapi-assertions
======================================

1.0.0(11mo ago)0114[1 PRs](https://github.com/Phauthentic/phpunit-openapi-assertions/pulls)MITPHPPHP ^8.1CI passing

Since Jun 4Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/Phauthentic/phpunit-openapi-assertions)[ Packagist](https://packagist.org/packages/phauthentic/phpunit-openapi-assertions)[ RSS](/packages/phauthentic-phpunit-openapi-assertions/feed)WikiDiscussions master Synced 1mo ago

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

Open API Validation for PHPUnit Tests
=====================================

[](#open-api-validation-for-phpunit-tests)

This small library will make it very easy for you to validate your request and response objects against a given Open API Schemas.

Under the hood `league/openapi-psr7-validator` is used but abstracted in a way that it can be replaced with any other implementation.

Testing the OpenAPI Schema
--------------------------

[](#testing-the-openapi-schema)

- Your test case must use the [OpenAPIValidatorTrait](src/OpenAPIValidatorTrait.php) or extend [App\\Tests\\ApiTestCase](../tests/ApiTestCase.php)
- Your test case must instantiate and set the [App\\Tests\\OpenAPISchemaValidator](../tests/OpenAPISchemaValidator.php) with the right schema. If you don't do this, the next steps will fail with an exception.
- Call `assertRequestMatchesOpenAPISchema($request)` to validate the request against the OpenAPI schema.
- Call `assertResponseMatchesOpenAPISchema($response)` to validate the response against the OpenAPI schema.

### Example:

[](#example)

```
use Phauthentic\PHPUnit\OpenAPIValidator\OpenAPIValidatorTrait;

class MyTestCase extends TestCase
{
    use OpenAPIValidatorTrait;

    public function setUp(): void
    {
        parent::setUp();

        // Load your OpenAPI schema
        self::setOpenAPISchemaValidator = new OpenAPISchemaValidator(
            'path/to/openapi.yaml',
        );
    }

    public function testSomeAPIIntegration(): void
    {
        // Create a client and make a request or whatever your framework
        // provides you to make such calls.
        $client = $this->createClient();
        $client->request('POST', '/api/v1/products', [
            'productName' => 'PHP',
        ]);

        // Assert the request and response against the OpenAPI schema
        self::assertRequestMatchesOpenAPISchema($client->getRequest());
        self::assertResponseMatchesOpenAPISchema($client->getResponse());
            path: '/api/v1/follows',
            method: 'post'
        );
    }
}
```

Symfony Support
---------------

[](#symfony-support)

Symfony does not support the PSR-7 interface for requests and responses. This means that you cannot use the OpenAPISchemaValidator directly in your Symfony tests. This package provides a workaround for this limitation by using the Symfony Bridge for PHPUnit. This bridge provides a way to use the PSR-7 interface in your Symfony tests.

You need to add those dependencies to your project via Composer:

- nyholm/psr7
- symfony/phpunit-bridge

Instead of using the OpenAPISchemaValidator use the OpenAPISymfonySchemaValidator in your test case.

```
self::setOpenAPISchemaValidator = new OpenAPISymfonySchemaValidator(
    'path/to/openapi.yaml',
);
```

License
-------

[](#license)

This bundle is under the [MIT license](LICENSE).

Copyright Florian Krämer

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance64

Regular maintenance activity

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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

348d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bef35c03b7865d9cad45c22e54eb6fe8f5fc84a4ff64d47cc0f7a1ef28dbe85?d=identicon)[floriankraemer](/maintainers/floriankraemer)

---

Top Contributors

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

---

Tags

phpunitphpunit-assertionstestingtesting-tools

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phauthentic-phpunit-openapi-assertions/health.svg)

```
[![Health](https://phpackages.com/badges/phauthentic-phpunit-openapi-assertions/health.svg)](https://phpackages.com/packages/phauthentic-phpunit-openapi-assertions)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

78768.9M1.5k](/packages/phpstan-phpstan-symfony)[instaclick/php-webdriver

PHP WebDriver for Selenium 2

43661.8M22](/packages/instaclick-php-webdriver)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)

PHPackages © 2026

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