sayuprc/http-test-case
最新稳定版本:v4.0.0
Composer 安装命令:
composer require sayuprc/http-test-case
包简介
Library for HTTP testing
README 文档
README
English | 日本語
sayuprc/http-test-case
A library for HTTP testing.
Requirements
| name | version |
|---|---|
| PHP | ^8.3 |
| PHPUnit | ^12.0 |
Installation
composer require --dev sayuprc/http-test-case
Usage
Extend the HttpTestCase class and implement the following methods:
getClient()getRequestFactory()getUriFactory()getStreamFactory()
<?php use GuzzleHttp\Client; use GuzzleHttp\Psr7\HttpFactory; use HttpTest\HttpTestCase; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; class SampleTest extends HttpTestCase { protected function getClient(): ClientInterface { return new Client(); } protected function getRequestFactory(): RequestFactoryInterface { return new HttpFactory(); } protected function getUriFactory(): UriFactoryInterface { return new HttpFactory(); } protected function getStreamFactory(): StreamFactoryInterface { return new HttpFactory(); } }
Testing a GET Request
<?php use HttpTest\HttpTestCase; class SampleTest extends HttpTestCase { public function testGet() { $response = $this->get('https://example.com'); $response->assertStatusCode(200); } }
Testing a POST Request
<?php use HttpTest\HttpTestCase; class SampleTest extends HttpTestCase { public function testPost() { $response = $this->post( 'https://example.com', [ 'headers' => [ 'Content-Type' => 'application/json', ], 'json' => [ 'key' => 'value', ], ] ); $response->assertStatusCode(200); } }
Documents
Please refer to the here for the methods and assertions of HttpTestCase.
统计信息
- 总下载量: 84
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-31