net*_*djw 3 testing laravel laravel-testing laravel-8
在我的 Laravel 项目中,我想测试一个 JSON 响应,它实际上是带有data键的分页器结果。它是一个数组,包含一些元素。我们不知道确切的数量,因为它来自一个函数。
我的问题是,如果分页限制为 10,并且我将元素数量更改为超过分页限制(例如 20),我仍然只能返回 10 个元素。但我也想测试一下。
现在我有这个代码:
$response
->assertSuccessful()
->assertJson(function (AssertableJson $json) use ($allElementsCount) {
$json
->has('data')
->whereType('data', 'array')
// here I want to test the count of 'data' array
->etc();
});
Run Code Online (Sandbox Code Playgroud)
如何测试 JSON 响应中的数组计数?