Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pionl/laravel-swagger-test
Test your routes using Laravel's underlying request testing (without making real request) against your API schema.
https://github.com/pionl/laravel-swagger-test
api laravel openapi phpunit swagger testing-tools
Last synced: 3 months ago
JSON representation
Test your routes using Laravel's underlying request testing (without making real request) against your API schema.
- Host: GitHub
- URL: https://github.com/pionl/laravel-swagger-test
- Owner: pionl
- Created: 2020-04-22T10:41:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-04T16:33:01.000Z (almost 4 years ago)
- Last Synced: 2024-08-06T20:20:50.666Z (5 months ago)
- Topics: api, laravel, openapi, phpunit, swagger, testing-tools
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Laravel Swagger Test
> Underlying logic uses [PHP Swagger Test](https://github.com/byjg/php-swagger-test) from [byjg](https://github.com/byjg)
Test your routes using Laravel's underlying request testing (without making real request) against your API schema.
## Support
> How to make tests and which OpenAPI is supported check the [PHP Swagger Test](https://github.com/byjg/php-swagger-test).
At the time of writing this readme OpenAPI 3 is partially supported.
## Install
1. Add a custom repository for php-swagger-test with internal improvements. (In future it could be merged).
```
"repositories": [
{
"type": "git",
"url": "https://github.com/pionl/php-swagger-test"
}
]
```
2. Require the package
```
compsoer require pion/laravel-swagger-test
```
## Usage
Use the Laravel's TestCase and use `AssertRequestAgainstSchema` trait assert request against schema.
Uses same "request building" as `ApiRequester`. For more details check the [PHP Swagger Test](https://github.com/byjg/php-swagger-test).
```php
use Tests\TestCase;
use ByJG\ApiTools\AssertRequestAgainstSchema;
use ByJG\ApiTools\Base\Schema;
use ByJG\ApiTools\Laravel\LaravelRequester;class GetUsersTest extends TestCase
{
use AssertRequestAgainstSchema;
/**
* Loaded schema for phpunit instance.
*
* @var Schema|null
*/
public static $cachedSchema = null;protected function setUp()
{
parent::setUp();// Load only once, must be made in setup to be able to use base_path
if (null !== $this->schema) {
return;
}// Load only once per phpunit instance
if (null === self::$cachedSchema) {
self::$cachedSchema = Schema::getInstance(file_get_contents(base_path('docs/api.json')));
}// Set the schema
$this->setSchema(self::$cachedSchema);
}public function testGetUsersWithoutFiltersInElasticSearchAgainstSchema()
{
// Create data
$this->createUser();$request = new LaravelRequester($this);
$request
->withMethod('GET')
->withPath('/v1/users');$this->assertRequest($request);
}
}
```