jeudi 24 février 2022

Laravel 5.2: How to test helper function?

I'm new to laravel. I have read the laravel documentation on testing but I do not seem to understand it. Could someone guide me on the steps to test this helper function?

Below is the function.

function getUnreadInboxMessagesForAUserById($id)
{

    $past_period_months = Carbon::now()->subMonths(6);

    $message = App\Message::select("*")
    ->whereIn("conversation_id", App\Conversation::select("id")
    ->where([
        ["user_one", "=", $id],
        ["delete_user_one", "=", 0]
    ])
    ->where(function($query) {
        $query->where("created_at", ">", $user_one_convo_deleted_at)->orWhereNull("user_one_convo_deleted_at");
    })
    ->where(function($query) {
        $query->where("created_at", ">", $user_one_msgs_deleted_at)->orWhereNull("user_one_msgs_deleted_at");
    })
    ->orWhere(function($query) {
        $query->where([
        ["user_two", "=", $id],
        ["delete_user_two", "=", 0]
        ])
        ->where(function($query) {
        $query->where("created_at", ">", $user_two_convo_deleted_at)->orWhereNull("user_two_convo_deleted_at");
        })
        ->where(function($query) {
        $query->where("created_at", ">", $user_two_msgs_deleted_at)->orWhereNull("user_two_msgs_deleted_at");
        });
    })
    )
    ->where([
    ["is_seen", "=", 0],
    ["user_id", "<>", $id]
    ])
    ->whereNotIn("user_id", App\DeactivateAccount::select("user_id"))
    ->where(function($query) {
    $query->whereNotIn("user_id", App\User::select("id")
        ->where([
        ["flag", "=", 0],
        ["id", "=", $user_id]
        ])
        ->orWhereIn("user_id", App\User::select("id")
            ->where("id", "=", $user_id)
            ->whereIn("membership", ["admin","premium","free-premium","diamond"]))
        );
    })
    ->where(function($query) {
    $query->where("hard_delete", "=", 0)->orWhereNull("hard_delete");
    })
    ->where(function($query) {
    $query->where("deleted_from_receiver", "=", 0)->orWhereNull("deleted_from_receiver");
    })
    ->where(function($query) {
    $query->where("isflaged", "!=", 1)->orWhereNull("isflaged");
    })
    ->where("created_at", ">=", $past_period_months)
    ->orderBy("created_at", "desc")
    ->get()
    ->count();

    return $messages[0];
}

It would be really helpful if you could list the steps in detail.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire