We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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