how do I mock the DB facade in laravel?
<p>I'm writing my unit tests and by default they should not hit the database. 
by general rule I always use eloquent to get the results, but some more complex queries I have to use the raw DB</p>

<p>I have this function:</p>

<pre><code>public function GetPassword($email)
{
    $result = DB::table('vin_user_active')
        -&gt;select(
            "vin_user_active.id",
            "vin_user_active.password",
            DB::raw('COALESCE(
                vin_user_active.pass_update_date &lt;=
                CURRENT_TIMESTAMP -
                INTERVAL vin_org_active.password_expiration_days DAY, 0
        ) AS password_expired')
        )
        -&gt;join('vin_org_active', "vin_user_active.org", "=", "vin_org_active.id")
        -&gt;where("email", "=", $email)
        -&gt;first();

    return $result;
}
</code></pre>

<p>Right now I'm mocking the GetPassword function, but 
1. I think the function should be private, not public. 
2. The coverage is just %50 because is skipping the whole function.</p>

<p>How would I mock it? right now I have this</p>

<pre><code>$this-&gt;db =Mockery::mock('Illuminate\Database\Query\Builder')-&gt;makePartial();

    DB::shouldReceive('table')
        -&gt;once()
        -&gt;with("vin_user_active")
        -&gt;andReturn($this-&gt;db);

    DB::shouldReceive('raw')
        -&gt;once()
        -&gt;with(Mockery::any())
        -&gt;andReturn(true);

    DB::shouldReceive('select')
        -&gt;once()
        -&gt;with("vin_user_active.id,
            vin_user_active.password,
            DB::raw('COALESCE(
                vin_user_active.pass_update_date &lt;=
                CURRENT_TIMESTAMP -
                INTERVAL vin_org_active.password_expiration_days DAY, 0
        ) AS password_expired'")
        -&gt;andReturn($this-&gt;db);
</code></pre>

<p>I honestly have no idea what I'm doing, I've never mocked so many levels of function calls.</p>

<p>any idea?</p>