承接 sayuprc/http-test-case 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-31