我试图利用Laravel的seeJson方法来检查集合响应,但它似乎并没有像我期望的那样工作。为什么它以这种方式工作,我该怎么做才能正确测试?
Unable to find JSON fragment [[{"created_at":"2016-03-05 15:12:46","email":"batz.aracely@yahoo.com","id":1,"name":"Mr. Enrique Wehner DVM","updated_at":"2016-03-05 15:12:46"}]] within [[{"created_at":"2016-03-05 15:12:46","email":"batz.aracely@yahoo.com","id":1,"name":"Mr. Enrique Wehner DVM","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"halvorson.gaston@hayes.org","id":9,"name":"Talon Monahan I","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"ilynch@gmail.com","id":2,"name":"Araceli Gulgowski","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"kattie.stracke@aufderhar.com","id":10,"name":"Baylee Abshire Jr.","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"lenore08@klein.com","id":4,"name":"Nicola Gusikowski","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"reilly.trace@yahoo.com","id":5,"name":"Doris Sauer Sr.","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"rhegmann@hotmail.com","id":6,"name":"Camilla Romaguera","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"robel.dortha@hotmail.com","id":3,"name":"Dr. Eudora Turcotte DVM","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"vturner@hamill.com","id":8,"name":"Ashton Shields","updated_at":"2016-03-05 15:12:46"},{"created_at":"2016-03-05 15:12:46","email":"walsh.herman@gmail.com","id":7,"name":"Devyn Bradtke","updated_at":"2016-03-05 15:12:46"}]].
Failed asserting that false is true.
测试和控制器代码:
public function testSeeingUserList()
{
$users = factory(App\User::class, 10)->create();
$this->get('/users/')
->seeJson($users->toArray());
}
public function listUsers()
{
return App\User::all();
}