PHPackages                             tunezilla/openapi-test-validation - 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. [API Development](/categories/api)
4. /
5. tunezilla/openapi-test-validation

ActiveLibrary[API Development](/categories/api)

tunezilla/openapi-test-validation
=================================

Easy OpenAPI Validation for Laravel tests

v1.1.1(3y ago)310.1kMITPHPPHP &gt;=7.4

Since May 4Pushed 3y ago2 watchersCompare

[ Source](https://github.com/tunezilla/openapi-test-validation)[ Packagist](https://packagist.org/packages/tunezilla/openapi-test-validation)[ RSS](/packages/tunezilla-openapi-test-validation/feed)WikiDiscussions master Synced 1mo ago

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

OpenAPI Request and Response Validation for Laravel Tests
=========================================================

[](#openapi-request-and-response-validation-for-laravel-tests)

This package allows you to perform OpenAPI request and response validation in Laravel tests while using the normal `$this->get()`, `$this->json()`, and `$this->call()` functions from the `MakesHttpRequests` trait.

This package does not currently have a Laravel version restriction. It is tested with Laravel 8.

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

[](#installation)

`composer require --dev tunezilla/openapi-test-validation`

Gotchas
-------

[](#gotchas)

The response body is consumed using [symfony/psr-http-message-bridge](https://github.com/symfony/psr-http-message-bridge/blob/2bead2266bbff6b138f2c8967e609d0c4e5307b8/Factory/PsrHttpFactory.php#L135) in order to validate that it matches the OpenAPI schema.

If you're testing responses that only send content once (like a [Symfony StreamedResponse](https://github.com/symfony/http-foundation/blob/c0bf3e7fdca5a396464148eb8a63356028a9cdb9/StreamedResponse.php#L99)) but try to retrieve this content in your test: OpenAPI validation has already occurred, the content has already been read, and you will receive an empty body.

Regular non-streamed responses are not affected by this issue.

Usage
-----

[](#usage)

1. Add the `MakesOpenAPIRequests` trait to your `TestCase`
2. Before sending a request, call `$this->openAPI('./path/to/your/openapi.yaml')` (chainable)

### Single Schema

[](#single-schema)

```
