Laravel 的 TestCase 方法 seeJson() 只查找数组
2022-08-30 23:43:54
我使用的是Laravel 5.1 Testsuite。
现在,我使用seeJson()方法测试我的json api。此方法需要一个数组,例如:
->seeJson(['created' => 1]);
但是我的 json api 总是返回一个 json 对象或一个包含 json 对象的数组,在这种情况下:
Response::json(['created' => 1], 200);
在上面的例子中,我的json api返回:
{created: 1}
但是 seeJson() 会精确地查找给定的数组:
[created: 1]
我从来没有通过比赛通过我的测试。如何匹配?