PHPackages                             gertjuhh/symfony-openapi-validator - 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. gertjuhh/symfony-openapi-validator

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

gertjuhh/symfony-openapi-validator
==================================

OpenAPI validator for Symfony application tests

0.2.7(5mo ago)8142.9k↓57.6%1[3 PRs](https://github.com/gertjuhh/symfony-openapi-validator/pulls)MITPHPPHP ^8.1CI passing

Since Mar 16Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/gertjuhh/symfony-openapi-validator)[ Packagist](https://packagist.org/packages/gertjuhh/symfony-openapi-validator)[ RSS](/packages/gertjuhh-symfony-openapi-validator/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (9)Dependencies (6)Versions (13)Used By (0)

OpenAPI validation for Symfony application tests
================================================

[](#openapi-validation-for-symfony-application-tests)

This package can validate requests made in application tests, based of Symfony's `WebTestCase`, against OpenAPI specifications. This is done by converting `HttpFoundation` objects using the [PSR-7 Bridge](https://symfony.com/doc/current/components/psr7.html) and passing them to the [OpenAPI PSR-7 Message Validator](https://github.com/thephpleague/openapi-psr7-validator).

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

[](#installation)

```
composer require --dev gertjuhh/symfony-openapi-validator

```

Usage
-----

[](#usage)

- Add the `OpenApiValidator` trait to your `WebTestCase`
- Create a client by calling `self::createClient()`
    - Alternatively use your own custom logic creating an instance of `KernelBrowser`
- Execute the request you wish to validate using the client
- Call `self::assertOpenApiSchema(, );`
    - `schema`: path to corresponding OpenAPI yaml schema
    - `client`: the client used to make the request
- Or optionally use the `self::assertResponseAgainstOpenApiSchema(, );` to only validate the response
    - The `operationAddress` can be passed as a third argument for this function but by default it will retrieve the operation from the `client`.

### Setting up a cache

[](#setting-up-a-cache)

The [underlying library can use a PSR-6 cache](https://github.com/thephpleague/openapi-psr7-validator#caching-layer--psr-6-support). This provides a significant speedup when running multiple tests against a single schema, since it can be parsed once and reused.

In order to activate this cache, you can pass a PSR-6 cache instance to the static property `\Gertjuhh\SymfonyOpenapiValidator\StaticOpenApiValidatorCache::$validatorCache`. For example:

```
