Laravel Тесты Утверждение Странно Возвращает Ложь - PullRequest
0 голосов
/ 25 февраля 2020

У меня есть тест json, который подтверждает, что ответ json равен assertsExact Json. Вот мой тест

class ContestantTest extends TestCase
{
    use DatabaseMigrations;

    /** @test */
    public function users_can_view_nominated_contestants()
    {
        $contest = factory(Contest::class)->create();
        $contestant = factory(Contestant::class)->create();
        $contest->contestants()->attach($contestant, [
           'votes' => 4
        ]);

        $nominated_contestants = ContestantResource::collection($contest->contestants);

        $response = $this->get('api/v1/nominated-contestants');
        $response->assertStatus(200)
             ->assertExactJson(['contestants' => $nominated_contestants])
             ;

    }
}

И это моя функция контроллера

public function getNominatedContestants()
    {
        $today = new Carbon();
        $contest = Contest::where($today, '<=', 'end_date')->first();
        $nominated_contestants = ContestantResource::collection($contest->contestants);
        return response()->json(['contestants' => $nominated_contestants]);
}

Вот мой точный ответ теста

1) Tests\Feature\ContestantTest::users_can_view_nominated_contestants
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'{"contestants":[{"firstName":"Lauren","lastName":"Murazik","dob":"1977- 
07-30","occupation":"Boxer","description":"Iure pariatur omnis asperiores 
a aliquid eos tempora. 
Repudiandae qui aperiam deleniti ad cumque excepturi vero 
qui.","nominationStatus":"1","state":"New 
Mexico","contestantId":"RlJjK"}]}'
+'{"contestants":[{"contestantId":"RlJjK","description":"Iure pariatur 
omnis asperiorui.","dob":"1977-0730","firstName":"Lauren","lastName":"Murazik","nominationStatus":"1","occupation":"Boxer","state":"New Mexico"}]}'

Возвращенные данные такие же, но устроен по-другому (странно). Как я могу это исправить?

...