OpenAPITools / OpenAPITools/openapi-generator

[REQ] PHPUnit test generation

Open
#4,336 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

no

Describe the solution you'd like

From the API definition it is possible to generate general end-to-end API tests in a PHPUnit compatible class format. All general things could be an object to be tested. Example: API returns a Content-Type: this could be tested.

Describe alternatives you've considered

Along with the given API specs it is possible to write API tests manually.

Additional context

This is how to test an endpoint that will respond with 405 on a PUT request:

public function testPut() {
    $response = $this->http->request('PUT', 'user-agent', ['http_errors' => false]);
    $this->assertEquals(405, $response->getStatusCode());
}

Maybe this is related to #566 but the solution there looks like it is related to slim framework only.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the OpenAPI definition and the generator's PHP output path, then review how generated API tests could represent general response checks. Compare the desired PHPUnit-compatible class with the linked Guzzle example; done means a defined generation scope and working PHPUnit tests for the applicable endpoints.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php
Domain
api, testing, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.