How to mock pagination
Hi!
I am trying to mock my pagination. Here I have PostsRepository and in method all() there is code like this:
return $this->_post->paginate(20);
How could I test this?
In my test I have:
$posts = new Collection([new Post, new Post]);
$this->_repo->shouldReceive('all')->once()->andReturn($posts);
.. and this tests are failing with error:
Call to undefined method Illuminate\Database\Eloquent\Collection::links()
So, how to mock this paginator correctly?
Thanks
Update:
Got this with:
$posts = [new Post, new Post];
$links = '<ul><li>1</li><li>2</li></ul>';
$this->_repo
->shouldReceive('all')->once()->andReturn(Mockery::mock([
'getCollection' => $posts,
'links' => $links
]));
But still... is there some more elegant solution?
Please or to participate in this conversation.