vendredi 13 novembre 2020

Laravel assertDatabaseHas() failing

When I try to assertDatabaseHas() it fails returns all columns but not what I specified I assume this is the reason for it failing but I do not know why. How can I fix this test?

I am using laravel v6.x , DB_CONNECTION=":memory:" and use RefreshDatabase;

My test case:

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

    $group = factory(Group::class)->create();

    $this->post(route('apn_user_store'), [

        'Name' => 'new User',
        'GroupID' => $group->groupid,
        'Username' => 'test@example.org',
        'UserLimit' => 1000
    ]);

    $this->assertDatabaseHas('s_users',[
        'username' => 'new User',
        'groupid' => $group->groupid,
        'useremail' => 'test@example.org',
        'userlimit' => 1000
    ]);
}

Test returns:

Failed asserting that a row in the table [s_users] matches the attributes {
    "username": "new User",
    "groupid": 1,
    "useremail": "test@example.org",
    "userlimit": 1000
}.

Found similar results: [
    {
        "userid": "1",
        "created_at": "2020-11-13 14:46:59",
        "updated_at": "2020-11-13 14:46:59",
        "groupid": "1",
        "username": "new User",
        "useremail": null,
        "userlimit": "1000",
        "baselimit": "1000",
        "custom_field": null,
        "threshold1": "0",
        "threshold2": "0",
        "threshold3": "0",
        "threshold4": "0",
        "threshold5": "0",
        "is_soft_capped": "0",
        "oid": null,
        "status": "Active",
        "isActive": "1",
        "logged": null,
        "deleted_at": null
    }
].

Please do not judge for lack of best practice I am in the process of fixing it but need my test case to work before I can implement changes.

Aucun commentaire:

Enregistrer un commentaire