joshgallagher24
2 years ago

Lumen Fratcal Testing Error

Posted 2 years ago by joshgallagher24

Hello all,

I am testing features in my application and have ran into a problem. I have wrote this feature test:

public function a_collection_of_articles_are_returned_paginated()
    {
        $user = factory(User::class)->create();
        factory(Article::class, 25)->create();
        $genArticle = factory(Article::class)->create([
            'title' => 'Some title',
            'slug' => 'some-title',
        ]);

        $this->json('GET', '/articles?page=6')
            ->seeJson([
                'data' => [
                    'title' => $genArticle->title,
                    'slug' => $genArticle->slug,
                    'teaser' => $genArticle->teaser,
                    'body' => $genArticle->body,
                    'created_at' => $genArticle->created_at,
                    'updated_at' => $genArticle->updated_at,
                    'user' => [
                        'data' => [
                            'name' => $user->getFullName(),
                        ]
                    ]
                ],
                'meta' => [
                    'pagination' => [
                        'total' => 26,
                        'count' => 1,
                        'per_page' => 5,
                        'current_page' => 6,
                        'total_pages' => 6,
                        'links' => [
                            'previous' => 'http://joshuagallagherapi.dev/articles?page=5',
                        ]
                    ]
                ]
            ])
            ->assertResponseStatus(200);
    }

However, when I run it, I get this error from PHPUnit:

There was 1 failure:

1) Tests\Feature\ArticleTest::a_collection_of_articles_are_returned_paginated
Unable to find JSON fragment ["data":{"body":"Repudiandae ullam praesentium aut totam dolores. Consectetur doloribus temporibus unde unde est pariatur quas. Ea saepe rem quia sed voluptas quia aut. Facilis et error ea velit rerum aut labore.","created_at":"28\/10\/17","slug":"some-title","teaser":"Odio deserunt molestiae soluta sunt adipisci ipsam. Dolor sint fugit perspiciatis est quis dignissimos maxime. Magni laudantium expedita aperiam. Quos odio rem dolorem magnam accusamus sunt non.","title":"Some title","updated_at":"28\/10\/17","user":{"data":{"name":"Warren Corwin"}}}] within [{"data":[{"body":"Repudiandae ullam praesentium aut totam dolores. Consectetur doloribus temporibus unde unde est pariatur quas. Ea saepe rem quia sed voluptas quia aut. Facilis et error ea velit rerum aut labore.","created_at":"28\/10\/17","slug":"some-title","teaser":"Odio deserunt molestiae soluta sunt adipisci ipsam. Dolor sint fugit perspiciatis est quis dignissimos maxime. Magni laudantium expedita aperiam. Quos odio rem dolorem magnam accusamus sunt non.","title":"Some title","updated_at":"28\/10\/17","user":{"data":{"name":"Warren Corwin"}}}],"meta":{"pagination":{"count":1,"current_page":6,"links":{"previous":"http:\/\/localhost\/articles?page=5"},"per_page":5,"total":26,"total_pages":6}}}].
Failed asserting that false is true.

I believe I am getting this error because Fractal returns the data differently, but I am unsure on how to get the data to comply with the seeJson method.

Any help would be appreciated.

Please sign in or create an account to participate in this conversation.