php - PHPUnit - 尝试测试 json 数组中的键和值
问题描述
我有以下 Json 数组:
[
{
"ticket_id": 131,
"ticket_subject": "quasi",
"ticket_content": "However, everything is queer to-day.' Just then she walked up towards it rather timidly, saying to.",
"ticket_name": "Prof. Ellen Yost Jr.",
"ticket_email": "sosinski@example.org",
"ticket_status": 0,
"created_at": "2021-04-19 16:53:33",
"updated_at": "2021-04-19 16:53:33"
}
]
我正在尝试编写一个功能测试来检查它是否具有 'ticket_status' 键和0
.
到目前为止,在我的测试文件中,我有以下代码:
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class OpenTicketTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function testOpenTickets()
{
$this->get(route('tickets.open'))
->assertStatus(200)
->assertJsonStructure([
'*' => [
'ticket_id',
'ticket_subject',
'ticket_content',
'ticket_name',
'ticket_email',
'ticket_status',
'created_at',
'updated_at'
]
])->assertJson([
'ticket_status' => 0
]);
}
}
但是当我运行测试时,我在控制台中收到以下错误消息:
Unable to find JSON:
[{
"ticket_status": 0
}]
within response JSON:
[[]].
Failed asserting that an array has the subset Array &0 (
'ticket_status' => 0
).
--- Expected
+++ Actual
@@ @@
array (
- 'ticket_status' => 0,
)
任何人对使用正确的语法来检索所需结果有任何想法吗?
谢谢,
罗伯特
解决方案
推荐阅读
- django - Heroku 不会在 Django 上迁移模型
- git - 如何获得我在 Azure DevOps 存储库中提交的贡献?
- python - 为什么这个初学者 Python 字符串返回 0?
- less - windows 10 mobaxterm less - 有没有办法抑制它在每行之前放置的额外字符 - 看起来像终端控制字符
- jvm - Apache Nifi - 在没有任何下游处理器的情况下运行 getFile 处理器时会发生什么
- java - 大文件中的 Stax 解析器字符偏移溢出
- python - 如何解决 DataLoader 中的错误形状?
- switch-statement - switch 和 match 语法有什么区别?
- swiftui - 为什么要从缓存中删除图像?| 翠鸟
- mysql - 无法在专用服务器上导入 13Gb 数据库