0

I got this result after running Unit Test.

Result:

1) Tests\Functional\Controllers\Api\UsersControllerTest::testUsersIndex
Unable to find JSON fragment
[[{"email":"FRoAff4@mail.com","id":"706"}]]
within
[{"data":[],"draw":0,"error":"Not Found","recordsFiltered":0,"recordsTotal":1}].
Failed asserting that false is true.

Code:

$this->seeJsonContains([
  'id'    => $user->id,
  'email' => $user->email,
]);

If in parameter I add true it works. I do not understand the task parameter is the logical value(true, false) here.

After:

$this->seeJsonContains([
  'id'    => $user->id,
  'email' => $user->email,
 ], true);
Davron Achilov
  • 536
  • 4
  • 14

1 Answers1

0

The second paramater of seeJsonContains negates the assertion, meaning it will switch from assertTrue to assertFalse. Thats why your test is passing, because it will instead check that the response JSON does NOT contain the id and email.

To make your test pass make sure your UsersController@testUsersIndex returns the correct JSON.

In your case: [[{"email":"FRoAff4@mail.com","id":"706"}]]

Remul
  • 7,874
  • 1
  • 13
  • 30
  • If I added ```true```, it does not check. Such email and id (FRoAff4@mail.com","id":"706") exists or not. I think this email and ID does not exist. – Davron Achilov Oct 22 '18 at 06:09