在我的 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();
});
如何在 JSON 回應中測驗陣列計數?
uj5u.com熱心網友回復:
您可以使用
$response->assertJsonCount(10, 'data');
參考
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/341081.html
