@isamirsalehi What’s a “repository pattern” got to do with how you test a controller? Just test it like you would any other scenario:
public function testExample(): void
{
$this->get('/uri')->assertOk();
}
If your repository is resolved by the container, you can mock it and set some expectations:
public function testListingOrders(): void
{
$this->mock(OrderRepository::class, function ($mock) {
$mock->shouldReceive('all')->once()->andReturn(new Collection());
});
$this->get('/orders')->assertOk();
}
But this is just testing how your code’s put together, and not if your code actually works in my opinion. If you re-factor your controller, your test is going to break, because it’s asserting how you’ve coded your controller and not how your controller is actually working.
For example, if you remove the repository and just use an Eloquent model and return the same data as the repository, the controller would still be working, but your test would break.