princeoo7
364
14
Laravel

Whats wrong with my test case in TDD ? Please help me understand !

Posted 5 months ago by princeoo7

I am new to TDD and was trying out test in practice and came across this failure. can some one assist me on understanding the error ?

//Terminal

PHPUnit 7.5.6 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 848 ms, Memory: 18.00 MB

There was 1 failure:

1) Tests\Feature\ArticleTest::a_user_can_create_a_article
Failed asserting that a row in the table [articles] matches the attributes {
    "title": "Demo Article Title 1",
    "slug": "demo-article-title-1",
    "banner": "https:\/\/placehold.it\/600x600",
    "description": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure atque repellat perspiciatis ducimus, ea architecto dolor cupiditate! Autem aperiam similique libero rerum minima quis. Sunt sit possimus soluta modi esse.",
    "category_id": 1,
    "status": 2,
    "author_id": 1,
    "moderator_id": 1,
    "created_at": "2019-03-05 18:42:27",
    "updated_at": "2019-03-05 18:42:27"
}.

Found: [
    {
        "id": 1,
        "title": "Demo Article Title 1",
        "slug": "demo-article-title-1",
        "banner": "https:\/\/placehold.it\/600x600",
        "description": null,
        "category_id": "1",
        "body": null,
        "views": 1,
        "status": 2,
        "author_id": 1,
        "moderator_id": 1,
        "created_at": "2019-03-05 18:42:27",
        "updated_at": "2019-03-05 18:42:27"
    }
].

C:\xampp\htdocs\pdpv2\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase.php:24
C:\xampp\htdocs\pdpv2\tests\Feature\ArticleTest.php:41

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
The terminal process terminated with exit code: 1

and

//ArticleTest.php

/** @test */
public function a_user_can_create_a_article()
{
    $this->withoutExceptionHandling();

    $this->actingAs(factory('App\User')->create());

    $attributes = [
        'title' => 'Demo Article Title 1',
        'slug' => 'demo-article-title-1',
        'banner' => 'https://placehold.it/600x600',
        'description' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure atque repellat perspiciatis ducimus, ea architecto dolor cupiditate! Autem aperiam similique libero rerum minima quis. Sunt sit possimus soluta modi esse.',
        'category_id' => 1,
        'status' => 2,
        'author_id' => auth()->id(),
        'moderator_id' => auth()->id(),
        'created_at' => date('Y-m-d H:i:s'),
        'updated_at' => date('Y-m-d H:i:s')
    ];

    $this->post('/articles', $attributes);

    $this->assertDatabaseHas('articles', $attributes);
}

please help me out with this error.

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