【发布时间】:2021-12-31 09:32:19
【问题描述】:
我正在尝试使用 PHPUnit 9.0.0 和 Symfony 5.1.8 执行我的第一个单元测试。如果 HTTP 响应为 200,则此测试必须通过。
<?php declare(strict_types=1);
namespace Tests\Infrastructure\Api\Controller;
use PHPUnit\Framework\TestCase;
class ControllerTests extends TestCase
{
/** @test */
public function route(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
我得到错误:
有 1 个错误:
- Tests\Infrastructure\Api\Controller\SupplierControllerTests::route 错误:调用未定义的方法 Tests\Infrastructure\Api\Controller\SupplierControllerTests::get()
我以为 Get 方法是默认方法,由 PHPUnit\Framework\TestCase 导入,但看起来不是这样。
我必须在我的类 ControllerTests 中添加一个 Get 方法吗?如何开发它来测试 HTTP 响应?
提前致谢
【问题讨论】: