4 months ago

Returning paginated results from a mocked repository

Posted 4 months ago by r123

View is failing to render because of what is returned from my mocked repository which makes the test fail. It works fine if I replace mocking with factory that adds entries to database.

In controller I am returning paginated collection.


public function index()
    $foos = $this->fooRepository->paginate();

    return view('foo.index', compact('foos'));


$mock = Mockery::mock(FooRepository::class);

$this->app->instance(FooRepository::class, $mock);

$response = $this->get(route('foo.index'));

$response->assertSuccessful(); // fails response is 500 and response contents has error that $foos is a string and cant call methods on it, etc.

This makes view to fail rendering because $foos inside it is a string for some reason.

What do I return from mocked repository to make the test pass?

Please sign in or create an account to participate in this conversation.