I wanna test a controller but I still don’t find a way to do it smoothly. For example, I wanna try a GET method with no parameters.
class HomeController extends BaseController
{
public function getHome(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$page = $request->getQueryParam('page', 1);
$polls = \App\Models\Poll::where('user_id', $_SESSION['user']['id'])->paginate(5, ['*'], 'page', $page);
$pages = $polls->links(new \Illuminate\Pagination\BootstrapFourPresenter($polls));
$data = ['polls' => $polls,
'pages' => $pages];
return $this->c->get('view')->render($response, 'home.twig', $data);
}
...
}
Nothing too complex going on (a page retrieves a collection of objects from the database based on a query) but I don’t get how to create a test for this that doesn’t involve creating a little new Slim app recreating everything from scratch. There’s very little information on how to test and the only thing I found is a case that’s too simple to fit this case.