Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Unit test controllers

How do you unit test controllers in Phalcon?

I have some trouble adding headers to a request, is it only possible to add these through the super global or is there some other way ?


i think you can do it through superglobal or through DI, something like:

// test case
$response = new \Phalcon\Http\Response();
$response->setHeader('Content-Type', 'application/json');
$this->getDI()->set('response', $response);

// dispatch

Yes that is possible in the response but not in the request :(

in that case you could create a mock object of request object and assign it to DI with key 'request' ?

Yes offcourse :D