Download the PHP package osteel/openapi-httpfoundation-testing without Composer

On this page you can find all versions of the php package osteel/openapi-httpfoundation-testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package openapi-httpfoundation-testing

OpenAPI HttpFoundation Testing

Build Status Latest Stable Version License Downloads

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

See this post for more details and this repository for an example use in a Laravel project.

[!IMPORTANT] While you can safely use this package for your projects, as long as version 1.0 has not been released "minor" version patches can contain breaking changes. Make sure to check the release section before you upgrade.

Why?

OpenAPI is a specification intended to describe RESTful APIs in a way that can be understood by both humans and machines.

By validating an API's requests and responses against the OpenAPI definition that describes it, we guarantee that the API is used correctly and behaves in accordance with the documentation we provide, thus making the OpenAPI definition the single source of truth.

The HttpFoundation component is developed and maintained as part of the Symfony framework. It is used to handle HTTP requests and responses in projects such as Symfony, Laravel, Drupal, and many others.

How does it work?

This package is built on top of OpenAPI PSR-7 Message Validator, which validates PSR-7 messages against OpenAPI definitions.

It converts HttpFoundation request and response objects to PSR-7 messages using Symfony's PSR-7 Bridge and Tobias Nyholm's PSR-7 implementation, before passing them on to OpenAPI PSR-7 Message Validator.

Installation

[!NOTE] This package is mostly intended to be used as part of an API test suite.

Via Composer:

Usage

Import the builder class:

Use the builder to create a \Osteel\OpenApi\Testing\Validator object, using one of the available factory methods for YAML or JSON:

[!TIP] You can also use a dependency injection container to bind the ValidatorBuilder class to the ValidatorBuilderInterface interface it implements and inject the interface instead, which would also be useful for testing and mocking.

You can now validate \Symfony\Component\HttpFoundation\Request and \Symfony\Component\HttpFoundation\Response objects for a given path and method:

[!TIP] For convenience, objects implementing \Psr\Http\Message\ServerRequestInterface or \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 (DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT and TRACE) also has a shortcut method that calls validate under the hood, meaning the line above could also be written this way:

Validating a request object works exactly the same way:

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

The validate method returns true in case of success, and throw a \Osteel\OpenApi\Testing\Exceptions\ValidationException exception in case of error.

Caching

This package supports caching to speed up the parsing of OpenAPI definitions. Simply pass your PSR-6 or PSR-16 cache object to the setCache method of the ValidatorBuilder class.

Here is an example using Symfony's Array Cache Adapter:

Extending the package

There are two main extension points – message adapters and cache adapters.

Message adapters

The HttpFoundationAdapter class as its default HTTP message adapter. This class converts HttpFoundation request and response objects to their PSR-7 counterparts.

If you need to change the adapter's logic, or if you need a new adapter altogether, create a class implementing the ValidatorBuilder class:

Cache adapters

The Psr16Adapter class as its default cache adapter. This class converts PSR-16 cache objects to their PSR-6 counterparts.

If you need to change the adapter's logic, or if you need a new adapter altogether, create a class implementing the ValidatorBuilder class:

Other interfaces

The ValidatorInterface interfaces respectively for which you can provide your own implementations if you need to.

Change log

Please see the Releases section for details.

Contributing

Please see CONTRIBUTING for details.

Credits

People

Special thanks to Pavel Batanov for his advice on structuring the package.

Packages

License

The MIT License (MIT). Please see License File for more information.


All versions of openapi-httpfoundation-testing with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
league/openapi-psr7-validator Version ^0.22
nyholm/psr7 Version ^1.3.1
psr/cache Version ^1.0 || ^2.0 || ^3.0
psr/http-message Version ^1.0 || ^2.0
psr/simple-cache Version ^1.0 || ^2.0 || ^3.0
symfony/cache Version ^5.0.9 || ^6.0 || ^7.0
symfony/http-foundation Version ^5.0.9 || ^6.0 || ^7.0
symfony/psr-http-message-bridge Version ^2.0 || ^6.0 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package osteel/openapi-httpfoundation-testing contains the following files

Loading the files please wait ....