restolia/http-testing

Restolia 应用程序的 HTTP 测试包。

0.0.2 2022-05-13 19:11 UTC

This package is auto-updated.

Last update: 2024-09-14 00:24:25 UTC


README

Restolia 应用的 Http 测试包,此包使您更容易为 Http 处理器编写测试。

入门

通过 Composer 安装

通过 Composer 在现有的 Restolia 项目中安装。

composer require restolia/http-testing

如何使用

要使用此包,请将以下特质 HttpAssertions 添加到您的 Restolia 项目中包含的 TestCase.php 文件中,此文件位于 tests/TestCase.php

示例

<?php

namespace Tests;

use App\App;
use Restolia\Kernel;
use Restolia\Testing\Http\HttpAssertions;

class TestCase extends \PHPUnit\Framework\TestCase
{
    use HttpAssertions;

    ...
}

示例

假设我们有一个名为 StatusHandler 的简单处理器,并且当我们的应用程序的 "/" 端点被调用时将执行此处理器。我们希望断言响应的 Http 状态码为 200 OK。

为此,我们可以编写以下代码

<?php

namespace Tests\Application\Handlers;

use Tests\TestCase;

class StatusHandlerTest extends TestCase
{
    public function testHandleDoesReturnOk(): void
    {
        $this->get('/')->assertOk();
    }
}