Mocked Eloquent Model returns array instead of Model
<p><strong>Strange problem</strong>: The method <code>first</code> of the mocked model returns an <em>array</em> instead of the <em>model</em>.</p>
<p>See the code below (Laravel + Eloquent + PHPUnit + Mockery).</p>
<h1>Eloquent Model</h1>
<pre><code>public function getByEmail(string $email) : User
{
    return $this-&gt;whereHas('emails', function ($query) use ($email) {
        $query-&gt;where('email', $email);
    })-&gt;first();
}
</code></pre>
<p>This works fine. It returns a model of type User.</p>
<h1>Repository</h1>
<pre><code>public function getByEmail(string $email) : array
{
    return $this-&gt;model-&gt;getByEmail($email)-&gt;toArray();
}
</code></pre>
<p>Which works fine too :-)</p>
<h1>Test with Mockery</h1>
<pre><code>/** @test */
public function it_fetches_an_user_by_email()
{
    $email = 'foo@bar.foo';

    $this-&gt;userMock
        -&gt;shouldReceive('getByEmail')
        -&gt;once()
        -&gt;with($email)
        -&gt;andReturn(['user' =&gt; 'foo']);

    $userRepository = new UserEloquentRepository($this-&gt;userMock);
    $this-&gt;assertArrayHasKey('user', $userRepository-&gt;getByEmail($email));
}
</code></pre>
<p><strong>My problem now:</strong>: The method <code>first</code> of the mocked model returns an <em>array</em> instead of the <em>model</em>.</p>