I need to test my controller action and i need advice. It's how my controller looks:
class SampleController extends Controller
{
public function sampleAction(Request $request)
{
$lang = 'en';
return $this->render('movie.html.twig', [
'icons' => $this->container->getParameter('icons'),
'language' => $lang,
'extraServiceUrl' => $this->getAccount()->getExtraServiceUrl(),
'websiteUrl' => $this->getAccount()->getWebsiteUrl(),
'myProfileUrl' => $this->getAccount()->getMyProfileUrl(),
'redirectForAnonUser' => $this->container->get('router')->generate('login'),
'containerId' => $request->getSession()->get("_website"),
'isRestricted' => $this->getLicense()->isRestricted(),
'isPremiumAvaible' => $this->getLicense()->isPremiumAvaible()
]);
}
private function getAccount()
{
return $this->container->get('context')->getAccount();
}
private function getLicense()
{
return $this->container->get('license');
}
}
And now, normally I test controllers by behat, but this one just render twig and set variables in so I probably can't test it by behat. I tried to test it by phpUnit and it can work, but what is the best way to mock chain methods? Or maybe you have other way to test it? btw container is private so I need reflection? Greetings