I am quite lost with how I should test the constructor. I have basic knowledge of how test are suppose to work but in this case, I do not know how I should proceed.
I have a constructor that handles rest request.
public function getStuffAction(Request $request) {
$searchString = $request->query->get('q', '');
if ($searchString === '')
$stuff = $this->getManager('stuff')->findAll();
else
$stuff = $this->getManager('stuff')->findBySearchString($searchString);
$view = View::create();
$view->setData($stuff)->setStatusCode(200);
return $view;
}
public function getManager($entityName) {
return $this->get('app.' . $entityName . '.manager');
}
I understand that I need to test the behaviour of my function. I see that I should test when the query is empty, when it is not and probably if it return something.
Be aware that I am new to Symfony.
From what I read, I should inject the manager as a parameter in getStuffAction so it can then be mocked but I don't know how.
Aucun commentaire:
Enregistrer un commentaire