- display errors We are currently conducting unit tests arou...">

PHPUnit Zend Framework controller tests - failed to use last used controller <"error"> - display errors

We are currently conducting unit tests around zend framework controllers.

(I was a little distracted by this sample code, but the idea is the same ....)

We successfully dealt with a test error with an error message

Failed asserting last controller used <"error"> ....

with test:

 $this->dispatch('/controller/action/param'); $this->assertController('controller'); $this->assertAction('action'); 

So, in this case, how can I get a real error message before PHPUnit, that is, if there is an error in the controller, I want to know about it, and not call the error controller.

If I set resources.frontController.params.noErrorHandler = 1 in application.ini, the test passes, even if there is an error, because this controller and action is still happening, but just doesnโ€™t output anything (I know that I could look for statements on the output, but this is not the point - I want the original error).

I tried to enable

 convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" 

in phpunit.xml, without joy.

Any pointers would be much appreciated.

I hope it all made sense !?

Thank you very much.

+4
source share
2 answers

Unfortunately, Zend_Test_PHPUnit_ControllerTestCase explicitly overrides some frontcontroller parameters at the time of submission. The corresponding code bit is here:

 $controller = $this->getFrontController(); $this->frontController ->setRequest($request) ->setResponse($this->getResponse()) ->throwExceptions(false) ->returnResponse(false); 

Since this is done inside dispatch (), you have absolutely no chance to change the parameters.

One solution I used was to create my own ControllerTestCase database, which extends Zend and copies the entire dispatch () function from the Zend object, and then changes one line.

It is dirty, but it works. You can make a more complex version that reads something from a configuration, etc.

+5
source

This is a problem that I am facing, and sometimes it is difficult to find an error. One solution that I accidentally stumbled upon was that I changed the error controller to send an email in case of an error in our production environment, but I accidentally set it to send to the test environment, as well, and then when one of these errors occurred on unit test, I received an email with a detailed description of the error.

You do not need to use an email notification, but you may want to view the error log at http://framework.zend.com/manual/en/zend.log.writers.html . You could write errors to the log file, and then check the log file.

+1
source

All Articles