HTTP 测试 断言方法

响应断言方法


assertCookie

断言响应包含给定 Cookie:

$response->assertCookie($cookieName, $value = null);

assertCookieExpired

断言响应包含给定 Cookie 并且已过期:

$response->assertCookieExpired($cookieName);

assertCookieNotExpired

断言响应包含给定 Cookie 并且没有过期:

$response->assertCookieNotExpired($cookieName);

assertCookieMissing

断言响应不包含给定 Cookie:

$response->assertCookieMissing($cookieName);

assertCreated

断言响应是否返回 201 状态码:

$response->assertCreated();

assertDontSee

断言给定字符串不在响应中:

$response->assertDontSee($value);

assertDontSeeText

断言给定字符串不在响应文本中:

$response->assertDontSeeText($value);

assertExactJson

断言响应与给定 JSON 数据完全匹配:

$response->assertExactJson(array $data);

assertForbidden

断言响应包含禁止状态码:

$response->assertForbidden();

assertHeader

断言给定头在响应中是否存在:

$response->assertHeader($headerName, $value = null);

assertHeaderMissing

断言给定头在响应中不存在:

$response->assertHeaderMissing($headerName);

assertJson

断言响应包含给定 JSON 数据:

$response->assertJson(array $data);

assertJsonCount

断言响应 JSON 包含给定键对应的指定条目数数组:

$response->assertJsonCount($count, $key = null);

assertJsonFragment

断言响应中包含给定 JSON 片段:

$response->assertJsonFragment(array $data);

assertJsonMissing

断言响应中不包含给定 JSON 片段:

$response->assertJsonMissing(array $data);

assertJsonMissingExact

断言响应中不包含给定完整的 JSON 片段:

$response->assertJsonMissingExact(array $data);

assertJsonMissingValidationErrors

断言响应中不包含给定键的 JSON 验证错误信息:

$response->assertJsonMissingValidationErrors($keys);

assertJsonPath

断言响应是否在指定路径包含给定数据:

$response->assertJsonPath($path, array $data, $strict = false);

assertJsonStructure

断言响应包含给定 JSON 结构:

$response->assertJsonStructure(array $structure);

assertJsonValidationErrors

断言响应包含给定键的 JSON 验证错误信息:

$response->assertJsonValidationErrors($keys);

assertLocation

断言在响应头 Location 中包含给定 URI 值:

$response->assertLocation($uri);

assertNoContent

断言响应包含给定状态码但没有任何内容:

$response->assertNoContent($status = 204);

assertNotFound

断言在响应包含 Not Found 状态码:

$response->assertNotFound();

assertOk

断言在响应包含 200 状态码:

$response->assertOk();

assertPlainCookie

断言响应包含给定 Cookie(未加密):

$response->assertPlainCookie($cookieName, $value = null);

assertRedirect

断言响应重定向到给定 URI:

$response->assertRedirect($uri);

assertSee

断言给定字符串包含在响应中:

$response->assertSee($value);

assertSeeInOrder

断言给定字符串有序包含在响应中:

$response->assertSeeInOrder(array $values);

assertSeeText

断言给定字符串包含在响应文本中:

$response->assertSeeText($value);

assertSeeTextInOrder

断言给定字符串有序包含在响应文本中:

$response->assertSeeTextInOrder(array $values);

assertSessionHas

断言会话中包含给定数据片段:

$response->assertSessionHas($key, $value = null);

assertSessionHasInput

断言会话中上次输入数组包含给定值:

$response->assertSessionHasInput($key, $value = null);

assertSessionHasAll

断言会话中存在给定值列表:

$response->assertSessionHasAll(array $data);

assertSessionHasErrors

断言会话中包含给定字段的错误信息:

$response->assertSessionHasErrors(array $keys, $format = null, $errorBag = 'default');

assertSessionHasErrorsIn

断言会话中包含给定错误:

$response->assertSessionHasErrorsIn($errorBag, $keys = [], $format = null);

assertSessionHasNoErrors

断言会话中不包含错误:

$response->assertSessionHasNoErrors();

assertSessionDoesntHaveErrors

断言会话中不包含给定键对应的错误信息:

$response->assertSessionDoesntHaveErrors($keys = [], $format = null, $errorBag = 'default');

assertSessionMissing

断言会话中不包含给定键:

$response->assertSessionMissing($key);

assertStatus

断言响应中包含给定状态码:

$response->assertStatus($code);

assertSuccessful

断言响应中包含成功状态码:

$response->assertSuccessful();

assertUnauthorized

断言响应中包含未授权(401)状态码:

$response->assertUnauthorized();

assertViewHas

断言响应视图包含给定数据片段:

$response->assertViewHas($key, $value = null);

此外,视图数据也可以通过数组变量方式在响应中访问:

$this->assertEquals('Taylor', $response['name']);

assertViewHasAll

断言响应视图包含给定数据列表:

$response->assertViewHasAll(array $data);

assertViewIs

断言给定视图由该路由返回:

$response->assertViewIs($value);

assertViewMissing

断言响应视图不包含绑定数据片段:

$response->assertViewMissing($key);

查看笔记

扫码一下
查看教程更方便