laravel - 调用未定义的方法 ExampleTest::assertStatus()
问题描述
我正在使用 Lumen 进行 api 构建,并且还想为此编写单元测试用例。但我面临的问题不是单一的断言方法正在工作。像assertStatus()
, assertNotFound()
,assertJson()
等。所有这些都给出错误作为调用未定义方法 ExampleTest::assertMethod()。下面是我的 ExampleTest 文件。
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->get('/');
$this->assertEquals(
$this->app->version(), $this->response->getContent()
);
}
/** @test */
public function testExample2()
{
$response = $this->get('/');
//getting error here
$response->assertStatus(200);
}
}
我第一次在 Lumen 编写测试用例。请指导我完成这个过程。
解决方案
如果您使用 LumenLaravel\Lumen\Testing\TestCase
与 Laravel 的 default ,一些断言方法会有所不同Illuminate\Foundation\Testing\TestCase
。
如果你想断言状态Illuminate\Foundation\Testing\TestCase
:
public function testHomePage()
{
$response = $this->get('/');
$response->assertStatus(200);
}
相同的Laravel\Lumen\Testing\TestCase
:
public function testHomePage()
{
$response = $this->get('/');
$this->assertEquals(200, $this->response->status());
}
推荐阅读
- microsoft-graph-api - Microsoft Graph API - 如何找出个人驱动器中更改的文件?
- ansible - Ansible:如何处理当前用户没有读取权限的文件(模式`0o600`)?
- angular - 使用ngFor时如何为cdkDropListConnectedTo设置Angular Material cdkDropList #name
- postgresql - 如何将表格的内容直接插入到另一个表格中?
- python - Shapley 值:解释 LSTM 预测时的维度问题
- arrays - MongoDB:如何计算两个对象内部的数组中的元素?
- javascript - 我的带有套接字 io 的烧瓶应用程序不允许使用 405 方法
- c# - 我可以将格式为 Mddyyy 的字符串转换为日期时间对象 c# 核心
- javascript - 在 Chrome 扩展内容脚本中注入 Popper.js
- swift - 何时何地在应用程序中查看订阅的到期日期和取消日期?