PHPackages                             goez/open-api-tester - 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. goez/open-api-tester

ActiveLibrary[API Development](/categories/api)

goez/open-api-tester
====================

2.1.0(2y ago)03.1kproprietaryPHPPHP 7.4|^8.1

Since Nov 6Pushed 2y agoCompare

[ Source](https://github.com/goez-tools/open-api-tester)[ Packagist](https://packagist.org/packages/goez/open-api-tester)[ Docs](https://web.kkbox.io/open-api-tester)[ RSS](/packages/goez-open-api-tester/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (6)Used By (0)

Open API Tester
===============

[](#open-api-tester)

Test API output format using Open API Spec 3 document.

Branches
--------

[](#branches)

- `1.x`: Supports PHP 7.2.
- `2.x`: Supports PHP 7.4 and above.

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

[](#installation)

Install this package into your project:

```
composer require goez/open-api-tester --dev
```

Generate an API documentation example and a PHPUnit test case in your Laravel project:

```
php artisan vendor:publish --tag=open-api-tester
```

The command will generate the following files:

- `docs/api/*`: The API documentation example.
- `tests/Feature/OpenApiSchemaTest.php`: The PHPUnit test case.

Basic Usage
-----------

[](#basic-usage)

### Define a Test Case

[](#define-a-test-case)

In the operation level of the document, add an `x-api-tests` extended field. Inside it, list one or more test cases in an array format.

The format of a test case is as follows:

```
  - type: request_test_case
    value:

      # Which response this test corresponds to
      response: 200

      # Description of this test (optional)
      description: "Test post user data"

      # Overriding parameter values (optional)
      # Defaults are taken from the parameters field of the operation
      # But if listed here, it overrides the default
      parameters:
        - name: some_parameter
          in: query
          value: some_value

      # Mock object outputs (optional)
      # Used to declare the output content of certain objects; multiple can be declared
      # Only its value will be retrieved in the test, requires additional handling through code
      mocks:
        - type: guzzle
          value: post_200_v1_login

      # Pre-test hook (optional)
      # Called before the test is executed, can be given a string or an array of PHP callable definitions
      setUp: ExampleClass::setUp

      # Post-test hook (optional)
      # Called after the test is executed, can be given a string or an array of PHP callable definitions
      tearDown: ExampleClass::tearDown

      # Request body (optional)
      #
      # Request format. This will affect how the request content should be encoded before sending.
      # It will also generate the corresponding Header.
      # Supports application/json, multipart/form-data, application/x-www-form-urlencoded
      requestBody:
        type: application/json
        data:
          # Directly write structured request content in the format of `key: string`.
          username: "John"
          # Or use `key: { type: file }` to upload a file
          image:
            type: file
            path: ./uploaded_image.jpg
            filename: original_name.jpg
          # Or use `key: { type: array, data }` to represent an array
          array_data:
            type: array
            data:
              some_key: 1
              some_other_key:
                - a
                - b
                - c
```

### Retrieving Test Cases

[](#retrieving-test-cases)

```
use Goez\OpenAPI\Tester\TestSuite;
use Goez\OpenAPI\Tester\TestCase;

// Parse the entire API document to get the test suite
$testSuite = TestSuite::loadFromYamlFile(
  __DIR__ . '/docs/api.yaml', // Document location
  'My API Tests',             // Test suite name
  __DIR__ . '/test_files/'    // External file path (Where to find the test files for testing uploads)
);

// Get warnings from the parsing process, which can be echoed to notify developers.

// Currently, warnings are generated when:
//   - No tests are defined for an Operation
$warnings = $testSuite->getWarning();

// Retrieve the test cases
// An array of Goez\OpenAPI\Tester\TestCase
$testCases = $testSuite->getTestCases();

foreach ($testCases as $testName => $testCase) {
  // Use the information contained in `$request` to make an HTTP call to your API or mock the Controller directly.
  $request = $testCase->getRequest();

  // Here, we use the fictitious function `callMyApi` to represent it. You'll need to implement it yourself.
  // If you're using Laravel, more information is provided below.
  $response = callMyApi($request);

  // Here are some commonly used methods:
  //
  // $request->getPath();
  // $request->getMethod();
  // $request->getQuery();
  // $request->getRequestBody();
  // $request->getHeader();

  // Verify if the actual response matches the definition
  $result = $testCase->validate($response->code, $response->body, TestCase::FORMAT_JSON);

  // Check if the validation was successful
  assert($result->isValid(), true);

  // Print out the validation details
  echo $result->renderReport();
}
```

Using Laravel/Lumen with PHPUnit
--------------------------------

[](#using-laravellumen-with-phpunit)

### Define a PHPUnit Test Case

[](#define-a-phpunit-test-case)

You can refer this file `tests/Feature/OpenApiSchemaTest.php`.

### Organizing the Request Format

[](#organizing-the-request-format)

Laravel doesn't actually send out HTTP requests, but instead creates a Request object and feeds it directly to the Laravel app for processing.

So, it's important to note the following:

- The request content doesn't need to be compiled into the actual format (JSON, urlencoded, etc); it can be directly inserted into the `$parameters` parameter in the form of a PHP array.
- For file uploads, use the `Illuminate\Http\UploadedFile` object. Both the `$parameters` and `$files` fields should contain a copy.
- You can use the `transformHeadersToServerVars` method built into Laravel TestCase to convert the header part of the request into the `$server` variable. In this example, we convert the test request into a format that Laravel can easily digest:

```
public function extractRequestInfo(\Goez\OpenAPI\Tester\Request\Request $request): array
{
    $files = [];
    $body = [];

    $server = $this->transformHeadersToServerVars($request->getHeader());
    $requestBody = $request->getRequestBody();

    if ($requestBody === null) {
        return [$body, $files, $server];
    }

    $body = collect($requestBody->getStructuredData())
        ->map(function ($item, $name) use (&$files) {
            if (is_a($item, \Goez\OpenAPI\Tester\Request\UploadedFile::class)) {
                // Convert the `UploadedFile` object into the `Illuminate\Http\UploadedFile`
                $uploadedFile = new \Illuminate\Http\UploadedFile(
                    $item->getPath(),
                    $item->getClientOriginalName(),
                    $item->getClientMimeType(),
                    null,
                    true
                );

                $files[$name] = $uploadedFile;

                return $uploadedFile;
            }

            return $item;
        })->toArray();

    return [$body, $files, $server];
}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

5

Last Release

905d ago

Major Versions

1.x-dev → 2.1.02023-11-22

PHP version history (2 changes)2.0.0PHP 7.4|^8.1

1.0.0PHP &gt;=7.2 &lt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/000012ed8f10873694d29e2f60b7b71171c088d6fd655a695210dd2fe46172b9?d=identicon)[jaceju](/maintainers/jaceju)

---

Top Contributors

[![jaceju](https://avatars.githubusercontent.com/u/310474?v=4)](https://github.com/jaceju "jaceju (8 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/goez-open-api-tester/health.svg)

```
[![Health](https://phpackages.com/badges/goez-open-api-tester/health.svg)](https://phpackages.com/packages/goez-open-api-tester)
```

###  Alternatives

[cebe/php-openapi

Read and write OpenAPI yaml/json files and make the content accessable in PHP objects.

49815.4M86](/packages/cebe-php-openapi)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[devizzent/cebe-php-openapi

Read and write OpenAPI yaml/json files and make the content accessable in PHP objects.

379.0M49](/packages/devizzent-cebe-php-openapi)[canvural/php-openapi-faker

Library to generate fake data for OpenAPI request/response/schemas.

92395.8k2](/packages/canvural-php-openapi-faker)[nfephp-org/sped-cte

API para geração e comunicação da CTe com as SEFAZ autorizadoras.

113227.7k1](/packages/nfephp-org-sped-cte)[tomaj/nette-api

Nette api

36261.8k4](/packages/tomaj-nette-api)

PHPackages © 2026

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