Download the PHP package greensight/laravel-openapi-testing without Composer
On this page you can find all versions of the php package greensight/laravel-openapi-testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-openapi-testing
Laravel OpenApi Testing
Deprecated, use https://github.com/ensi-platform/laravel-openapi-testing instead
This packages is based on osteel/openapi-httpfoundation-testing
and provides ValidatesAgainstOpenApiSpec
trait
Installation
You can install the package via composer:
composer require greensight/laravel-openapi-testing
Basic usage
Let's add validation according to oas3 to our tests.
All we need is to use ValidatesAgainstOpenApiSpec;
and implement getOpenApiDocumentPath(): string
method like that:
The trait overrides $this->call
method to add the needed validation
As a result all http related helper methods ($this->get()
, $this->postJson()
and e.t.c) perform the validation too.
Both request and response is validated to match some part of the given spec. If validation fails your tests is automatically marked as failed, no need to need any manual assertions.
Turning validation off
In some cases you may want to turn validation for a specific request. Here is an exanple how to do it:
Mapping paths
In order to validate request against oas3 the package need to map it to one of the paths described in specification document.
We use path from Laravel's route ($request->route()->uri
) for that purpose.
If it does not fully match in your case you can explicitly set OpenApi path for the current request like that:
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- npm i
- composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.