-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assertExactJson - False-Positive running #25960
Comments
it works when I static defined.
|
This is because |
By definition, a json object is unordered.
Maybe the assertion should take that into account? |
I opened an issue the other week related to this as well #25769 I'm also having issues with |
I have repaired it and you can close the issues @sfatihk |
Thank you for repair, my friend @HongjiangHuang . But the problem still exists on my test case. I included your changes #26315, didn't work, Best way to test this situation seems like to still write manual json format & sorted values. I simplified the problem. public function test_show_func_can_return_true_city(){
//city model( id, name )
$city = App\City::create(['name'=>'Istanbul']);
$city_from_db = App\City::find($city->id);
$response = new TestResponse((new JsonResponse([$city])));
$response->assertExactJson([$city_from_db]);
//->assertJson([$city_from_db]);
//$this->json('GET', '/api/cities/'.$city->id)->assertExactJson(['status' => 'success','data' => $city]);
} output: There was 1 failure:
1) Tests\Unit\app\Http\Controller\Region\CityControllerTest::test_show_func_can_return_true_city
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'[{"id":1,"name":"Istanbul","created_at":"2018-11-13 10:36:30","updated_at":"2018-11-13 10:36:30"}]'
+'[{"created_at":"2018-11-13 10:36:30","id":1,"name":"Istanbul","updated_at":"2018-11-13 10:36:30"}]'
C:\laragon\www\gs-api\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:461
C:\laragon\www\gs-api\tests\Unit\app\Http\Controllers\Region\CityControllerTest.php:41
FAILURES!
Tests: 1, Assertions: 1, Failures: 1. |
I really don't see the problem here. I agree that the spec says it should be unordered by why don't you just use |
@sfatihk You can try
|
assertjson was printing same error.
Thanks again my friend, @HongjiangHuang |
Description:
I saw this error message when testing my City Model resource show route.
Note: Database freshing after test. And i'm using sqlite for testing but i tested this situation on Mysql; anything change.
Error Message
City Model
City Controller Show function
Test Function
Beautified JSON response
Exactly same data but different sorting. Why it acting like this ?
The text was updated successfully, but these errors were encountered: