ensi/laravel-openapi-testing
Composer 安装命令:
composer require ensi/laravel-openapi-testing
包简介
laravel openapi testing
README 文档
README
This packages is based on ensi/openapi-httpfoundation-testing and provides ValidatesAgainstOpenApiSpec trait
Installation
You can install the package via composer:
composer require ensi/laravel-openapi-testing --dev
Version Compatibility
| Laravel OpenApi Testing | PHP |
|---|---|
| ^0.1.0 | ^8.0 |
| ^0.2.0 | ^8.0 |
| ^0.3.0 | ^8.0 |
| ^0.4.0 | ^8.1 |
Basic usage
Let's add validation according to oas3 to our tests.
All we need is to use ValidatesAgainstOpenApiSpec; and implement getOpenApiDocumentPath(): string method like that:
class SomeTestCase extends AnotherTestCase { use ValidatesAgainstOpenApiSpec; protected function getOpenApiDocumentPath(): string { return public_path('api-docs/v1/index.yaml'); } }
The trait overrides $this->call method to add the needed validation
As a result all http related helper methods ($this->get(), $this->postJson() and e.t.c) perform the validation too.
Both request and response is validated to match some part of the given spec. If validation fails your tests is automatically marked as failed, no need to need any manual assertions.
Turning validation off
In some cases you may want to turn validation for a specific request. Here is an example how to do it:
// Turn off validation for both request $this->skipNextOpenApiRequestValidation()->getJson(...); // Turn off validation for both response $this->skipNextOpenApiResponseValidation()->getJson(...); // Turn off validation for both request and response $this->skipNextOpenApiValidation()->getJson(...);
Mapping paths
In order to validate request against oas3 the package need to map it to one of the paths described in specification document.
We use path from Laravel's route ($request->route()->uri) for that purpose.
If it does not fully match in your case you can explicitly set OpenApi path for the current request like that:
$this->forceOpenApiPath('/pets/{petId}')->getJson(...);
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
ensi/laravel-openapi-testing 适用场景与选型建议
ensi/laravel-openapi-testing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ensi/laravel-openapi-testing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ensi/laravel-openapi-testing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 77.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-05