{"id":15965486,"url":"https://github.com/ovr/swagger-assert-helper","last_synced_at":"2025-05-07T06:06:12.162Z","repository":{"id":57034370,"uuid":"60911479","full_name":"ovr/swagger-assert-helper","owner":"ovr","description":":rainbow: Test your API by Swagger like a god on the :rocket:","archived":false,"fork":false,"pushed_at":"2019-06-25T18:46:47.000Z","size":219,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T06:06:06.923Z","etag":null,"topics":["php","swagger","swagger-php-asserter","swagger-scheme","swagger-validator"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ovr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-11T14:40:34.000Z","updated_at":"2020-10-18T12:16:28.000Z","dependencies_parsed_at":"2022-08-23T20:50:33.559Z","dependency_job_id":null,"html_url":"https://github.com/ovr/swagger-assert-helper","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovr%2Fswagger-assert-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovr%2Fswagger-assert-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovr%2Fswagger-assert-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovr%2Fswagger-assert-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ovr","download_url":"https://codeload.github.com/ovr/swagger-assert-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823918,"owners_count":21809713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","swagger","swagger-php-asserter","swagger-scheme","swagger-validator"],"created_at":"2024-10-07T17:41:43.718Z","updated_at":"2025-05-07T06:06:12.137Z","avatar_url":"https://github.com/ovr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Swagger Assert Helper\n=====================\n[![Build Status](https://travis-ci.org/ovr/swagger-assert-helper.svg?branch=master)](https://travis-ci.org/ovr/swagger-assert-helper)\n\nThis library bring support for:\n \n- Making HTTP Request by Swagger Path\n- Asserting HTTP Response with Swagger Response Scheme\n- Functional testing on top of frameworks: `Zend`, `Laravel`, `Slim`, `Symfony`\n- Integration testing on top of: `Guzzle`\n\n## Installing via Composer\n\nYou can use [Composer](https://getcomposer.org) .\n\n```bash\ncomposer require ovr/swagger-assert-helper\n```\n\n# How to use?\n\n# 1. Write Swagger Definition for your API:\n\nI love to use PHP comments, example:\n\n```php\n/**\n * @SWG\\Definition(\n *  definition = \"UserResponse\",\n *  required={\"id\", \"name\"},\n *  @SWG\\Property(property=\"id\", type=\"integer\", format=\"int64\"),\n *  @SWG\\Property(property=\"name\", type=\"string\"),\n * );\n */\nclass UserController extends AbstractController\n{\n    /**\n     * @SWG\\Get(\n     *  tags={\"User\"},\n     *  path=\"/user/{id}\",\n     *  operationId=\"getUserById\",\n     *  summary=\"Find user by $id\",\n     *  @SWG\\Parameter(\n     *      name=\"id\",\n     *      description=\"$id of the specified\",\n     *      in=\"path\",\n     *      required=true,\n     *      type=\"string\"\n     *  ),\n     *  @SWG\\Response(\n     *      response=200,\n     *      description=\"success\",\n     *      @SWG\\Schema(ref=\"#/definitions/UserResponse\")\n     *  ),\n     *  @SWG\\Response(\n     *      response=404,\n     *      description=\"Not found\"\n     *  )\n     * )\n     */\n    public function getAction() {}\n}\n```\n\nMore definition examples you can find in:\n\n- [Example/API](examples/api) - example of small HTTP REST service by PHP comments\n- [Example/GitHub](examples/github) - example definitions for `api.github.com` by PHP comments\n\n# 2. Write test for your Controller\n\n## Functional\n\nFunctional - when you execute `Request` inside your service (`PHP` code), there are support for:\n\n- Symfony by [SymfonyTrait](src/SymfonyTrait.php)\n- Laravel by [LaravelTrait](src/LaravelTrait.php)\n- Zend by [ZendTrait](src/ZendTrait.php)\n- Slim by [SlimTrait](src/SlimTrait)\n\nExample:\n\n```php\nclass UserControllerTest extends \\PHPUnit\\Framework\\TestCase\n{\n    // You should use trait for your framework, review supported and use what you need\n    use \\Ovr\\Swagger\\SymfonyTrait;\n    \n    public function testGetUserById()\n    {\n        // We define operation called getUserById in first step!\n        $operation = $this-\u003egetSwaggerWrapper()-\u003egetOperationByName('getUserById');\n        \n        // Call makeRequestByOperation from our framework Trait, SymfonyTrait for us\n        $request = $this-\u003emakeRequestByOperation(\n            $operation,\n            [\n                'id' =\u003e 1\n            ]\n        );\n        \n        // This will be \\Symfony\\Component\\HttpFoundation\\Request\n        var_dump($request);\n        \n        // You should execute your API module by Request and get Response\n        $response = $this-\u003egetApi()-\u003ehandle($request);\n        \n        $this-\u003egetSwaggerWrapper()-\u003eassertHttpResponseForOperation(\n            // Call makeRequestByOperation from our framework Trait, SymfonyTrait for us\n            $this-\u003eextractResponseData($response),\n            // getUserById\n            $operation,\n            // Operation can response by codes that your defined, lets assert that it will be 200 (HTTP_OK)\n            Response::HTTP_OK\n        );\n    }\n    \n    /**\n     * Return API module/service/bundle, that handle request and return Response for it\n     */\n    abstract public function getApi();\n\n    /**\n     * SwaggerWrapper store all information about API and help us with assertHttpResponseForOperation\n     *\n     * @return \\Ovr\\Swagger\\SwaggerWrapper\n     */\n    protected function getSwaggerWrapper()\n    {\n        return new \\Ovr\\Swagger\\SwaggerWrapper(\n            \\Swagger\\scan(\n                // Path to your API\n                __DIR__ . '/../../examples/api'\n            )\n        );\n    }\n}\n```\n\n## Integration\n\nIntegration - when you execute `Request` by real transport, there are support for:\n\n- Guzzle by [GuzzleTrait](src/GuzzleTrait.php)\n\n# FAQ\n\n\u003cdl\u003e\n  \u003cdt\u003eQ: Can this library validate my Swagger definition?\u003c/dt\u003e\n  \u003cdd\u003eA: No. This library validate your API requests and responses match your Swagger definition.\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003cdl\u003e\n  \u003cdt\u003eQ: What content types are supported?\u003c/dt\u003e\n  \u003cdd\u003eA: JSON for now, ask me for XML or something else in the issues.\u003c/dd\u003e\n\u003c/dl\u003e\n\n# LICENSE\n\nThis project is open-sourced software licensed under the MIT License.\n\nSee the [LICENSE](LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovr%2Fswagger-assert-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovr%2Fswagger-assert-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovr%2Fswagger-assert-helper/lists"}