minicli / pest-plugin-curly
在Pest测试中进行curl(y)请求
0.2.1
2023-04-14 19:32 UTC
Requires
- php: ^8.1
- minicli/curly: ^0.2.2
- pestphp/pest: ^2.0.0
- pestphp/pest-plugin: ^2.0.0
Requires (Dev)
- pestphp/pest-dev-tools: ^v2.6.0
This package is auto-updated.
Last update: 2024-09-14 22:48:39 UTC
README
此插件为Pest测试添加了基本的HTTP请求功能,使用minicli/curly。
安装
composer require minicli/pest-plugin-curly
使用方法
插件公开了3个测试用例方法
get()
matchResponse(string $endpoint, int code)
responseContains(string $endpoint, string $needle)
示例
<?php it('makes GET requests', function () { $this->get('https://api.github.com/rate_limit'); }); it('matches response codes', function () { $this->matchResponse('https://api.github.com/rate_limit', 200); }); it('matches strings in response body', function () { $this->responseContains('https://api.github.com/rate_limit', 'rate'); });
它还附带了一个快捷函数,您可以使用它来访问Curly客户端实例。如果您需要检查更多关于请求的信息、发送特殊头信息或需要执行Curly支持的其他类型的请求(如POST和DELETE),这非常有用。有关如何使用此库的更多信息,请参阅文档。
use function Minicli\PestCurlyPlugin\curly; it('makes requests using the curly() function to obtain response', function () { expect(curly()->get('https://api.github.com/rate_limit'))->toBeArray(); });