PHPackages                             ovr/swagger-assert-helper - 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. ovr/swagger-assert-helper

ActiveLibrary[API Development](/categories/api)

ovr/swagger-assert-helper
=========================

1.1.6(8y ago)36.7k2PHPPHP &gt;=5.6

Since Aug 28Pushed 7y ago2 watchersCompare

[ Source](https://github.com/ovr/swagger-assert-helper)[ Packagist](https://packagist.org/packages/ovr/swagger-assert-helper)[ RSS](/packages/ovr-swagger-assert-helper/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (10)Versions (15)Used By (0)

Swagger Assert Helper
=====================

[](#swagger-assert-helper)

[![Build Status](https://camo.githubusercontent.com/275781403b44b831e539dc3dbb0d155d747d8993ae333b34a5d9f84cabd90f59/68747470733a2f2f7472617669732d63692e6f72672f6f76722f737761676765722d6173736572742d68656c7065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ovr/swagger-assert-helper)

This library bring support for:

- Making HTTP Request by Swagger Path
- Asserting HTTP Response with Swagger Response Scheme
- Functional testing on top of frameworks: `Zend`, `Laravel`, `Slim`, `Symfony`
- Integration testing on top of: `Guzzle`

Installing via Composer
-----------------------

[](#installing-via-composer)

You can use [Composer](https://getcomposer.org) .

```
composer require ovr/swagger-assert-helper
```

How to use?
===========

[](#how-to-use)

1. Write Swagger Definition for your API:
=========================================

[](#1-write-swagger-definition-for-your-api)

I love to use PHP comments, example:

```
/**
 * @SWG\Definition(
 *  definition = "UserResponse",
 *  required={"id", "name"},
 *  @SWG\Property(property="id", type="integer", format="int64"),
 *  @SWG\Property(property="name", type="string"),
 * );
 */
class UserController extends AbstractController
{
    /**
     * @SWG\Get(
     *  tags={"User"},
     *  path="/user/{id}",
     *  operationId="getUserById",
     *  summary="Find user by $id",
     *  @SWG\Parameter(
     *      name="id",
     *      description="$id of the specified",
     *      in="path",
     *      required=true,
     *      type="string"
     *  ),
     *  @SWG\Response(
     *      response=200,
     *      description="success",
     *      @SWG\Schema(ref="#/definitions/UserResponse")
     *  ),
     *  @SWG\Response(
     *      response=404,
     *      description="Not found"
     *  )
     * )
     */
    public function getAction() {}
}
```

More definition examples you can find in:

- [Example/API](examples/api) - example of small HTTP REST service by PHP comments
- [Example/GitHub](examples/github) - example definitions for `api.github.com` by PHP comments

2. Write test for your Controller
=================================

[](#2-write-test-for-your-controller)

Functional
----------

[](#functional)

Functional - when you execute `Request` inside your service (`PHP` code), there are support for:

- Symfony by [SymfonyTrait](src/SymfonyTrait.php)
- Laravel by [LaravelTrait](src/LaravelTrait.php)
- Zend by [ZendTrait](src/ZendTrait.php)
- Slim by [SlimTrait](src/SlimTrait)

Example:

```
class UserControllerTest extends \PHPUnit\Framework\TestCase
{
    // You should use trait for your framework, review supported and use what you need
    use \Ovr\Swagger\SymfonyTrait;

    public function testGetUserById()
    {
        // We define operation called getUserById in first step!
        $operation = $this->getSwaggerWrapper()->getOperationByName('getUserById');

        // Call makeRequestByOperation from our framework Trait, SymfonyTrait for us
        $request = $this->makeRequestByOperation(
            $operation,
            [
                'id' => 1
            ]
        );

        // This will be \Symfony\Component\HttpFoundation\Request
        var_dump($request);

        // You should execute your API module by Request and get Response
        $response = $this->getApi()->handle($request);

        $this->getSwaggerWrapper()->assertHttpResponseForOperation(
            // Call makeRequestByOperation from our framework Trait, SymfonyTrait for us
            $this->extractResponseData($response),
            // getUserById
            $operation,
            // Operation can response by codes that your defined, lets assert that it will be 200 (HTTP_OK)
            Response::HTTP_OK
        );
    }

    /**
     * Return API module/service/bundle, that handle request and return Response for it
     */
    abstract public function getApi();

    /**
     * SwaggerWrapper store all information about API and help us with assertHttpResponseForOperation
     *
     * @return \Ovr\Swagger\SwaggerWrapper
     */
    protected function getSwaggerWrapper()
    {
        return new \Ovr\Swagger\SwaggerWrapper(
            \Swagger\scan(
                // Path to your API
                __DIR__ . '/../../examples/api'
            )
        );
    }
}
```

Integration
-----------

[](#integration)

Integration - when you execute `Request` by real transport, there are support for:

- Guzzle by [GuzzleTrait](src/GuzzleTrait.php)

FAQ
===

[](#faq)

 Q: Can this library validate my Swagger definition? A: No. This library validate your API requests and responses match your Swagger definition. Q: What content types are supported? A: JSON for now, ask me for XML or something else in the issues.LICENSE
=======

[](#license)

This project is open-sourced software licensed under the MIT License.

See the [LICENSE](LICENSE) file for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 99.4% 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

Every ~14 days

Recently: every ~6 days

Total

13

Last Release

3053d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c019ea1f0133ad14d256163bc4d25a428b15f08083b15fdd380dc215e0e26177?d=identicon)[ovr](/maintainers/ovr)

---

Top Contributors

[![ovr](https://avatars.githubusercontent.com/u/572096?v=4)](https://github.com/ovr "ovr (155 commits)")[![tombouctou](https://avatars.githubusercontent.com/u/529780?v=4)](https://github.com/tombouctou "tombouctou (1 commits)")

---

Tags

phpswaggerswagger-php-asserterswagger-schemeswagger-validator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ovr-swagger-assert-helper/health.svg)

```
[![Health](https://phpackages.com/badges/ovr-swagger-assert-helper/health.svg)](https://phpackages.com/packages/ovr-swagger-assert-helper)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k36.4M127](/packages/darkaonline-l5-swagger)[ronasit/laravel-swagger

Provided middleware for generating of swagger-documentation file by run testing of restful API.

179129.9k2](/packages/ronasit-laravel-swagger)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.7M4](/packages/cloudcreativity-json-api-testing)[litalico-engineering/eg-r2

Easy request validation and route generation from open API specifications (for Laravel)

1114.6k](/packages/litalico-engineering-eg-r2)

PHPackages © 2026

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