Ehh - don't unit test repositories. Write integration tests instead.
And, in this case, if you're trying to test User::findOrFail(1), there's no reason to bother. Eloquent already has tests.
I want to test a method called 'loadById', so I've written the following test:
<?php
use App\Models\User;
class TestDbUserRepository extends TestCase{
public function testCanLoadById()
{
$mock = Mockery::mock('App\Models\User');
$repository = new App\Repositories\User\DbUserRepository();
$mock->shouldReceive('findOrFail')->once()->with(1)->andReturn('hashed');
$user = $repository->loadById(1);
$this->assertEquals(new User(), $user);
}
}
In the DbUserRepository, i've only stubbed out the loadById method, but not added any logic at all.
The issue is that it doesn't seem to be checking to see if the findOrFail method on the model is being called at all.
Please or to participate in this conversation.