hamlet-framework/http-message-spec

Hamlet Framework / HTTP / 消息 / 规范

0.0.5 2024-03-01 01:08 UTC

This package is auto-updated.

Last update: 2024-08-30 04:00:50 UTC


README

Hamlet Framework / HTTP / 消息 / 规范

PSR-7 的测试用例集合。

如何使用

"require-dev": {
    ...
    "hamlet-framework/http-message-spec": "@stable",
    ...
}

如果您想测试您的 Psr\Http\Message\RequestInterface 实现,请创建一个测试用例并导入以下三个特质

class MyRequestTest extends TestCase
{
    use DataProviderTrait;
    use MessageTestTrait;
    use RequestTestTrait;

    ...
}

之后,您需要实现返回您 PSR-7 接口实现的 4 个抽象工厂方法

class MyRequestTest extends TestCase
{
    ...
    
    protected function request(): RequestInterface
    {
        return new MyRequest('GET', new Uri());
    }

    protected function message(): MessageInterface
    {
        return $this->request();
    }

    protected function stream(): StreamInterface
    {
        return MyStream();
    }

    protected function uri(string $value): UriInterface
    {
        return new MyUri($value);
    }

现在您可以运行您的测试了。

基准测试结果(PHP 8.3)

全面测试

+----------------------+--------------------+-------------------+--------------+
| Function description | Execution time (s) | Memory usage (mb) | Times faster |
+----------------------+--------------------+-------------------+--------------+
| ring-central         | 1.1089             | 0.1770            | 13%          |
| nyholm               | 1.2584             | 0.0870            | 20%          |
| http-soft            | 1.5183             | 0.1210            | 5%           |
| guzzle               | 1.6034             | 0.2050            | 18%          |
| hamlet-framework     | 1.8983             | 0.1700            | 51%          |
| zend-diactoros       | 2.8708             | 0.1730            | 8%           |
| wind-walker          | 3.1030             | 0.5210            | 0            |
+----------------------+--------------------+-------------------+--------------+

获取测试

+----------------------+--------------------+-------------------+--------------+
| Function description | Execution time (s) | Memory usage (mb) | Times faster |
+----------------------+--------------------+-------------------+--------------+
| hamlet-framework     | 0.5370             | 0.0000            | 13%          |
| ring-central         | 0.6111             | 0.0010            | 12%          |
| guzzle               | 0.6852             | 0.0000            | 8%           |
| nyholm               | 0.7433             | 0.0000            | 18%          |
| http-soft            | 0.8771             | 0.0000            | 33%          |
| zend-diactoros       | 1.1698             | 0.0000            | 32%          |
| wind-walker          | 1.5468             | 0.0000            | 0            |
+----------------------+--------------------+-------------------+--------------+

PHP 8.3 下的总测试失败数

+-----------------+-------+
| Hamlet          |     0 |
| Nyholm          |   108 |
| RingCentral     |   109 |
| Guzzle          |   111 |
| HttpSoft        |   124 |
| LaminasDiactoros |   140 |
+-----------------+-------+

待办事项