bauhaus / assert-psr-response
PHP 包,包含用于断言 PSR 响应的类
v1.0.0
2020-06-16 16:59 UTC
Requires
- php: >=7.4
- fefas/jsoncoder: ^v0.2
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.2
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-09-09 10:20:09 UTC
README
断言 PSR 响应
此 composer 包旨在提供一个简单的方式来断言 PSR-7 响应。
动机
我创建此包是因为在验收测试中,我经常需要断言 PSR 响应的特定值。
安装
使用 Composer 安装
$ composer require bauhaus/assert-psr-response
使用方法
<?php use Bauhaus\PsrResponseAssertion\PsrResponseAssertion; use Bauhaus\PsrResponseAssertion\Matchers\HeaderLine; use Bauhaus\PsrResponseAssertion\Matchers\StatusCode; $assertion = PsrResponseAssertion::with( StatusCode::equalTo(200), HeaderLine::equalTo('Content-Type', 'application/json') ); $psrResponse = // retrieve it from somewhere ... $psrResponse = $psrResponse ->withStatus(404) ->withHeader('Content-Type', 'text/html'); $assertion->assert($psrResponse); // throw PsrResponseAssertionException with message: // Actual response status code '404' is not equal to the expected '200' // Actual response header line 'Content-Type' 'text/html' is not equal to the expected 'application/json'
可用的匹配器
StatusCode::equalTo(200)
HeaderLine::equalTo('Header-Name', 'Header-Value')
JsonBody::equalTo('{"field":"value"}')
贡献
有两种方式可以为此项目做出贡献。第一种是通过在此 处 提交问题。第二种是通过编码。
- 在此项目上进行分支,并在本地开发环境中克隆
- 通过命令
composer install
安装依赖项 - 在提交拉取请求之前,在本地运行测试
- 要测试代码标准:
composer run test:cs
- 要运行单元测试:
composer run test:unit
- 要一次性运行所有测试:
composer run tests