Closed emir closed 7 years ago
Yes you can mock response. However, you need to pass exactly the same instance to the withPaginator
method when you try to test them using $response->shouldReceive('withPaginator')->with()
.
You test fail because the $barTransformer = new \Foo\Transformers\BarTransformer($paginator);
is not the same instance then the one created in your controller $this->response->withPaginator(Test::paginate(20), new BarTransformer());
. Same thing for Test::paginate(20)
.
I think the best way to resolve this is to validate the input like this $response->shouldReceive('withPaginator')->with(Mockery::type(LengthAwarePaginator::class), Mockery::type(BarTransformer::class))->andReturn('foo');
Hope it's make sense to you !
Hello! I try to test my controller but I couldn't mock response's withPaginator method. I saw that method coming from Laravel's specific Response class. So I don't know how can I test that response line. Should I change Interface or is there any clean way to do?
Here's the code I would like to tests:
It's my test method:
Runned test log:
Thanks for helping!