pion / laravel-swagger-test
Test your routes using Laravel's underlying request testing (without making real request) against your API schema.
Fund package maintenance!
pionl
revolut.me/martinpv7n
Installs: 3 826
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- byjg/swagger-test: dev-allow-custom-requester#8f2f8d2a927b2300e6a0bb09c54f8682d64a6e14
- laravel/framework: *
This package is auto-updated.
Last update: 2024-11-05 00:56:43 UTC
README
Underlying logic uses PHP Swagger Test from 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.
At the time of writing this readme OpenAPI 3 is partially supported.
Install
-
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" } ]
-
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.
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); } }