vfunin/laravel-openapi-testing 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vfunin/laravel-openapi-testing

最新稳定版本:1.2

Composer 安装命令:

composer require vfunin/laravel-openapi-testing

包简介

README 文档

README

This packages is based on osteel/openapi-httpfoundation-testing and provides ValidatesAgainstOpenApiSpec trait

Installation

You can install the package via composer:

composer require mib/laravel-openapi-testing

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

  1. composer install
  2. npm i
  3. composer test

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固