Thank you Hector.
A few minutes before your response I realised that. Typical! The error
handler is a plugin that works upon the response object from a
controller and thus logically will catch a controller or action error,
and that's it. Extra parameters depend upon the application design, not
the core framework. In getting there I discovered much about the
interconnection between the controller, the controller error handler
plugin, and the response object with its sub-class
Zend_Controller_Response_Http. I cannot overstate the benefits of unit
testing and TDD. Logical assumptions and manual reading are not quite
the same as arriving at a conclusion via direct testing!
The last part of unit testing the error controller I need to get my head
around is why the following code fails in a unit test but works with the
application...
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
On 24/11/2010 21:39, Hector Virgen wrote:
If you're using the default route, error/error/jg will route
successfully to the error controller's error action. This is why you
don't see the EXCEPTION_NO_CONTROLLER nor EXCEPTION_NO_ACTION errors.
If you look at the default errorAction() method provided by Zend_Tool,
you'll see that it defaults to a 500 error code even if no exception
was thrown.
There is nothing in the error controller that causes an exception to
be thrown if a bad parameter is passed -- you'll need to implement
this logic yourself.
I hope this helps!
--
*Hector Virgen*
Sr. Web Developer
http://www.virgentech.com
On Wed, Nov 24, 2010 at 9:48 AM, Mike A <[email protected]
<mailto:[email protected]>> wrote:
Moved on a bit with this. A bit confused, though, about the
$this->response->isException() flag and output under some
conditions of $this->getRequest()->getParam('error_handler')->type.
Example unit test for ErrorController...
public function testX() {
$this->dispatch('/error/error/jg');
echo "Response exception (boolean):
".$this->response->isException()."\n";
echo "Response code: ".
$this->response->getHttpResponseCode()."\n";
echo "Exception
dump:".var_dump($this->getRequest()->getParam('error_handler')->type)."\n";
}
If I set dispatch to provide a bad controller or action I get
isException flagged as boolean "1" and corresponding
getHttpResponseCode() and error handler type. For a bad controller
the values are "404" and "EXCEPTION_NO_CONTROLLER", and for a bad
action the same HttpResponseCode and "EXCEPTION_NO_ACTION".
If in dispatch I set correct controller and action but a bad
parameter, as in the above example unit test, I receive the
expected HttpResponseCode (500) but null values for isException
and the error_handler type. Why is this?
On 23/11/2010 20:26, Mike A wrote:
After 8pm here, suspect my two brain cells have given up, but
have to set up a walking skeleton...
I want to write a unit test to check two items.
1) The different error handler messages (like
Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER);
and 2) the HTTP error codes.
For an ErrorController action exception...
public function testX() {
$this->dispatch('/error/xxx');
...
}
How to get the error_handler result? In ErrorController it
starts with $errors = $this->_getParam('error_handler');
A practical example or pointer to one would be appreciated.
TIA...
Mike A.